Jyothirmai commited on
Commit
88e8671
·
verified ·
1 Parent(s): 2e77581

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
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
- with gr.Row():
37
- sample_images = [
38
- 'https://imgur.com/W1pIr9b',
39
- 'https://imgur.com/MLJaWnf',
40
- 'https://imgur.com/6XymFW1',
41
- 'https://imgur.com/zdPjZZ1',
42
- 'https://imgur.com/DKUlZbF'
43
- ]
44
-
45
-
46
- image = gr.Image(label="Upload Chest X-ray", type="pil")
47
-
48
- sample_images_gallery = gr.Gallery(value = sample_images,label="Sample Images")
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":