Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,11 @@ import gradio as gr
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# 1) ์ด๋ฏธ์ง ์บก์
๋ ํ์ดํ๋ผ์ธ ์ด๊ธฐํ
|
5 |
-
captioner = pipeline("image-
|
6 |
|
7 |
-
# 2)
|
8 |
def style_convert(raw_caption, style):
|
9 |
if style == "TOEIC Speaking Part 1":
|
10 |
-
# Partโฏ1: โWhat do you see in the picture?โ
|
11 |
-
# ๋ต๋ณ: โI see ~.โ ํ ๋ฌธ์ฅ
|
12 |
return f"Q: What do you see in the picture?\nA: {raw_caption.capitalize()}."
|
13 |
elif style == "IELTS Describe a Photo":
|
14 |
return f"Describe the photo in two sentences:\n1. {raw_caption.capitalize()}.\n2. It also shows the context of daily life."
|
@@ -17,9 +15,7 @@ def style_convert(raw_caption, style):
|
|
17 |
|
18 |
# 3) Gradio ์ธํฐํ์ด์ค ํจ์
|
19 |
def generate_caption(image, style):
|
20 |
-
|
21 |
-
result = captioner(image, max_length=30, num_beams=3)[0]["caption"]
|
22 |
-
# 3.2 ์คํ์ผ ๋ณํ
|
23 |
return style_convert(result, style)
|
24 |
|
25 |
# 4) Gradio Blocks ์ ์
|
@@ -36,6 +32,5 @@ with gr.Blocks() as demo:
|
|
36 |
btn = gr.Button("Generate")
|
37 |
btn.click(fn=generate_caption, inputs=[img_in, style_sel], outputs=output)
|
38 |
|
39 |
-
# 5) ์ฑ ์คํ
|
40 |
if __name__ == "__main__":
|
41 |
demo.launch()
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# 1) ์ด๋ฏธ์ง ์บก์
๋ ํ์ดํ๋ผ์ธ ์ด๊ธฐํ
|
5 |
+
captioner = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
6 |
|
7 |
+
# 2) ์คํ์ผ ๋ณํ ํจ์
|
8 |
def style_convert(raw_caption, style):
|
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 f"Describe the photo in two sentences:\n1. {raw_caption.capitalize()}.\n2. It also shows the context of daily life."
|
|
|
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 ์ ์
|
|
|
32 |
btn = gr.Button("Generate")
|
33 |
btn.click(fn=generate_caption, inputs=[img_in, style_sel], outputs=output)
|
34 |
|
|
|
35 |
if __name__ == "__main__":
|
36 |
demo.launch()
|