Juho Inkinen commited on
Commit
0e83ca4
·
1 Parent(s): 5c3f18e

Enhanced layout

Browse files
Files changed (1) hide show
  1. app.py +31 -10
app.py CHANGED
@@ -76,15 +76,36 @@ def process_image(image):
76
  return image, caption, subjects
77
 
78
 
79
- demo = gr.Interface(
80
- fn=lambda image: process_image(image)[1:], # Only return caption and subjects
81
- inputs=gr.Image(type="pil", label="Upload or take a photo"),
82
- outputs=[
83
- gr.Textbox(label="Caption"),
84
- gr.Label(label="Subject Suggestions", show_heading=False),
85
- ],
86
- title="VLM Caption & Annif Subject Demo",
87
- description="Upload or take a photo. The app generates a caption using a Visual Language Model and suggests subjects using Annif.",
88
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
 
90
  demo.launch()
 
76
  return image, caption, subjects
77
 
78
 
79
+ with gr.Blocks(title="VLM Caption & Annif Subject Demo") as demo:
80
+ gr.Markdown("# VLM Caption & Annif Subject Demo")
81
+ gr.Markdown(
82
+ """
83
+ **How it works:**
84
+ 1. Upload or take a photo in the input section below.
85
+ 2. The image is sent to a Visual Language Model to generate a caption.
86
+ 3. Annif suggests subjects based on the caption.
87
+ """
88
+ )
89
+ with gr.Row():
90
+ with gr.Column():
91
+ gr.Markdown("### Input")
92
+ image_input = gr.Image(
93
+ type="pil", label="Image Input (upload or take a photo)"
94
+ )
95
+ submit_btn = gr.Button("Submit")
96
+ clear_btn = gr.Button("Clear")
97
+ with gr.Column():
98
+ gr.Markdown("### Output")
99
+ caption_output = gr.Textbox(label="Caption", lines=10, interactive=False)
100
+ subjects_output = gr.Label(label="Subject Suggestions", show_heading=False)
101
+
102
+ def run_app(image):
103
+ caption, subjects = process_image(image)[1:]
104
+ return caption, subjects
105
+
106
+ submit_btn.click(
107
+ run_app, inputs=image_input, outputs=[caption_output, subjects_output]
108
+ )
109
+ clear_btn.click(lambda: ("", {}), outputs=[caption_output, subjects_output])
110
 
111
  demo.launch()