Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,12 +28,10 @@ TEMPLATES = {
|
|
28 |
"mountain": "In this picture, {caption}. The background looks like mountains, suggesting a hiking scene."
|
29 |
}
|
30 |
|
31 |
-
def generate_caption(
|
32 |
try:
|
33 |
-
# 1)
|
34 |
-
|
35 |
-
img_path = filepaths[idx]
|
36 |
-
img = Image.open(img_path).convert("RGB")
|
37 |
|
38 |
# 2) ์๋ณธ ์บก์
์์ฑ
|
39 |
out = captioner(img)
|
@@ -50,25 +48,15 @@ def generate_caption(filepaths, choice_index):
|
|
50 |
return template.format(caption=raw)
|
51 |
|
52 |
except Exception as e:
|
53 |
-
# ๋ฌธ์ ๊ฐ ์์ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฉ์์ง ๋ฐํ
|
54 |
return f"๐ด Error: {e}"
|
55 |
|
56 |
# 5) Gradio ์ธํฐํ์ด์ค ์ ์
|
57 |
with gr.Blocks() as demo:
|
58 |
-
gr.Markdown("## ๐ธ TOEIC Partโฏ1: ์ํฉ๋ณ ์ฌ์ง ๋ฌ์ฌ")
|
59 |
-
|
60 |
-
file_count="multiple",
|
61 |
-
type="filepath",
|
62 |
-
label="Upload up to 4 images"
|
63 |
-
)
|
64 |
-
choice = gr.Dropdown(
|
65 |
-
choices=[str(i) for i in range(4)],
|
66 |
-
value="0",
|
67 |
-
label="Which image to describe? (0โ3)"
|
68 |
-
)
|
69 |
btn = gr.Button("Describe")
|
70 |
output = gr.Textbox(label="TOEIC Partโฏ1 Response", lines=4)
|
71 |
-
btn.click(fn=generate_caption, inputs=
|
72 |
|
73 |
# 6) ์ฑ ์คํ
|
74 |
if __name__ == "__main__":
|
|
|
28 |
"mountain": "In this picture, {caption}. The background looks like mountains, suggesting a hiking scene."
|
29 |
}
|
30 |
|
31 |
+
def generate_caption(image_path):
|
32 |
try:
|
33 |
+
# 1) ์ด๋ฏธ์ง ๋ถ๋ฌ์ค๊ธฐ
|
34 |
+
img = Image.open(image_path).convert("RGB")
|
|
|
|
|
35 |
|
36 |
# 2) ์๋ณธ ์บก์
์์ฑ
|
37 |
out = captioner(img)
|
|
|
48 |
return template.format(caption=raw)
|
49 |
|
50 |
except Exception as e:
|
|
|
51 |
return f"๐ด Error: {e}"
|
52 |
|
53 |
# 5) Gradio ์ธํฐํ์ด์ค ์ ์
|
54 |
with gr.Blocks() as demo:
|
55 |
+
gr.Markdown("## ๐ธ TOEIC Partโฏ1: ์ํฉ๋ณ ์ฌ์ง ๋ฌ์ฌ (Single Image)")
|
56 |
+
img_in = gr.Image(type="filepath", label="Upload an image")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
btn = gr.Button("Describe")
|
58 |
output = gr.Textbox(label="TOEIC Partโฏ1 Response", lines=4)
|
59 |
+
btn.click(fn=generate_caption, inputs=img_in, outputs=output)
|
60 |
|
61 |
# 6) ์ฑ ์คํ
|
62 |
if __name__ == "__main__":
|