Update app.py
Browse files
app.py
CHANGED
@@ -33,28 +33,35 @@ with gr.Blocks() as demo:
|
|
33 |
gr.HTML("<p style='text-align: center;'>You can generate captions by uploading an X-Ray and selecting a model of your choice below</p>")
|
34 |
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
'https://imgur.com/
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
with gr.Row():
|
51 |
model_choice = gr.Radio(["CLIP-GPT2", "ViT-GPT2", "ViT-CoAttention"], label="Select Model")
|
52 |
|
53 |
generate_button = gr.Button("Generate Caption")
|
54 |
|
|
|
|
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
-
caption = gr.Textbox(label="Generated Caption")
|
58 |
|
59 |
def predict(img, model_name):
|
60 |
if model_name == "CLIP-GPT2":
|
|
|
33 |
gr.HTML("<p style='text-align: center;'>You can generate captions by uploading an X-Ray and selecting a model of your choice below</p>")
|
34 |
|
35 |
|
36 |
+
examples_list = [
|
37 |
+
['https://imgur.com/W1pIr9b', 'Caption for image 1'],
|
38 |
+
['https://imgur.com/MLJaWnf', 'Caption for image 2']
|
39 |
+
]
|
40 |
+
examples = gr.Examples(examples_list,
|
41 |
+
inputs="image",
|
42 |
+
outputs=["image", "text"],
|
43 |
+
label="Example Images",
|
44 |
+
fn=render_image
|
45 |
+
)
|
46 |
+
|
47 |
+
image_table = gr.Dataframe(headers=['image', 'caption'], datatype=['html', 'str'])
|
48 |
+
|
49 |
|
50 |
with gr.Row():
|
51 |
model_choice = gr.Radio(["CLIP-GPT2", "ViT-GPT2", "ViT-CoAttention"], label="Select Model")
|
52 |
|
53 |
generate_button = gr.Button("Generate Caption")
|
54 |
|
55 |
+
caption = gr.Textbox(label="Generated Caption")
|
56 |
+
|
57 |
|
58 |
+
# Function to populate table rows when an example image is clicked
|
59 |
+
def populate_table_from_example(image_path, caption):
|
60 |
+
new_row = [[render_image(image_path)], [caption]]
|
61 |
+
image_table.append(new_row)
|
62 |
+
|
63 |
+
examples.click(populate_table_from_example, inputs=examples, outputs=image_table)
|
64 |
|
|
|
65 |
|
66 |
def predict(img, model_name):
|
67 |
if model_name == "CLIP-GPT2":
|