englissi commited on
Commit
73e2c66
ยท
verified ยท
1 Parent(s): e4d072e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -18
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(filepaths, choice_index):
32
  try:
33
- # 1) ์„ ํƒ๋œ ์ด๋ฏธ์ง€ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
34
- idx = int(choice_index)
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
- img_inputs = gr.Files(
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=[img_inputs, choice], outputs=output)
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__":