Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,21 +4,33 @@ from transformers import pipeline
|
|
4 |
# 1) ์ด๋ฏธ์ง ์บก์
๋ ํ์ดํ๋ผ์ธ ์ด๊ธฐํ
|
5 |
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
if style == "TOEIC Speaking Part 1":
|
10 |
return f"Q: What do you see in the picture?\nA: {raw_caption.capitalize()}."
|
11 |
elif style == "IELTS Describe a Photo":
|
12 |
-
return
|
|
|
|
|
|
|
|
|
13 |
else:
|
14 |
return raw_caption
|
15 |
|
16 |
-
# 3) Gradio ์ธํฐํ์ด์ค ํจ์
|
17 |
-
def generate_caption(image, style):
|
18 |
-
result = captioner(image, max_length=30, num_beams=3)[0]["generated_text"]
|
19 |
-
return style_convert(result, style)
|
20 |
-
|
21 |
-
# 4) Gradio Blocks ์ ์
|
22 |
with gr.Blocks() as demo:
|
23 |
gr.Markdown("## ๐ธ ์ด๋ฏธ์ง ์บก์
๋ โ English Test ์คํ์ผ ๋ฌธ์ฅ ์์ฑ")
|
24 |
with gr.Row():
|
|
|
4 |
# 1) ์ด๋ฏธ์ง ์บก์
๋ ํ์ดํ๋ผ์ธ ์ด๊ธฐํ
|
5 |
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
6 |
|
7 |
+
def generate_caption(image, style):
|
8 |
+
# 1) ์๋ณธ ์บก์
์ป๊ธฐ
|
9 |
+
output = captioner(image)
|
10 |
+
# output ์์: [{"generated_text": "..."}] ๋๋ [{"text": "..."}] ํน์ ["..."]
|
11 |
+
# ์์ ํ๊ฒ ์ถ์ถ
|
12 |
+
if isinstance(output, list) and output:
|
13 |
+
first = output[0]
|
14 |
+
if isinstance(first, dict):
|
15 |
+
raw_caption = first.get("generated_text") or first.get("text") or ""
|
16 |
+
else:
|
17 |
+
raw_caption = str(first)
|
18 |
+
else:
|
19 |
+
raw_caption = str(output)
|
20 |
+
|
21 |
+
raw_caption = raw_caption.strip()
|
22 |
+
# 2) ์คํ์ผ ๋ณํ
|
23 |
if style == "TOEIC Speaking Part 1":
|
24 |
return f"Q: What do you see in the picture?\nA: {raw_caption.capitalize()}."
|
25 |
elif style == "IELTS Describe a Photo":
|
26 |
+
return (
|
27 |
+
"Describe the photo in two sentences:\n"
|
28 |
+
f"1. {raw_caption.capitalize()}.\n"
|
29 |
+
"2. It also shows the context of daily life."
|
30 |
+
)
|
31 |
else:
|
32 |
return raw_caption
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
with gr.Blocks() as demo:
|
35 |
gr.Markdown("## ๐ธ ์ด๋ฏธ์ง ์บก์
๋ โ English Test ์คํ์ผ ๋ฌธ์ฅ ์์ฑ")
|
36 |
with gr.Row():
|