englissi commited on
Commit
410aa7d
ยท
verified ยท
1 Parent(s): 8806737

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -2,13 +2,11 @@ import gradio as gr
2
  from transformers import pipeline
3
 
4
  # 1) ์ด๋ฏธ์ง€ ์บก์…”๋‹ ํŒŒ์ดํ”„๋ผ์ธ ์ดˆ๊ธฐํ™”
5
- captioner = pipeline("image-captioning", model="Salesforce/blip-image-captioning-base")
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
- # 3.1 ์ด๋ฏธ์ง€ ์บก์…”๋‹
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()