-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetadata-processing.py
More file actions
75 lines (59 loc) · 2.4 KB
/
Copy pathmetadata-processing.py
File metadata and controls
75 lines (59 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import base64
import json
from openai import OpenAI
import time
# --------------------
# Setup
# --------------------
with open("api-keys/openai-key.txt", 'r') as f:
openai_key = f.read()
openai_key = openai_key.strip()
client = OpenAI(api_key=openai_key)
# 입력: accesslens-metadata.json
with open("accesslens-metadata.json", "r") as f:
db = json.load(f)
enriched_docs = []
for obj, contexts in db.items():
for ctx, designs in contexts.items():
for i, d in enumerate(designs):
title = d.get("title", "")
image_url = d.get("image_url", "")
design_url = d.get("design_url", "")
prompt = f"""
You are helping enrich metadata for accessibility-related design objects.
Object: {obj}
Context: {ctx}
Title: {title}
Task: Based on the title, object, context, and the attached image, write a short natural language description (2–3 sentences).
The description should explain how the design works, what accessibility need it addresses, and in what situation it might be useful.
"""
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are an assistant generating enriched descriptions for accessibility design metadata."},
{"role": "user", "content": [
{"type": "text", "text": prompt},
{"type": "image_url", "image_url": {"url": image_url}}
]}
],
temperature=0.7
)
description = response.choices[0].message["content"]
except Exception as e:
print(f"Error on {design_url}: {e}")
description = ""
enriched_docs.append({
"id": f"{obj}__{ctx}__{i}",
"object": obj,
"context": ctx,
"title": title,
"description": description,
"design_url": design_url,
"image_url": image_url
})
time.sleep(1) # API rate-limit 보호용 (조정 가능)
# 출력: enriched_accesslens.json 저장
with open("enriched_accesslens.json", "w") as f:
json.dump(enriched_docs, f, indent=2, ensure_ascii=False)
print("✅ Enrichment complete! Saved to enriched_accesslens.json")