ryaalbr commited on
Commit
31a5db6
1 Parent(s): bee7306

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -30,8 +30,8 @@ def set_labels(text):
30
  return text.split(",")
31
 
32
  get_caption = gr.load("ryaalbr/caption", src="spaces", hf_token=environ["api_key"])
33
- def generate_text(image):
34
- return get_caption(image)
35
 
36
  with gr.Blocks() as demo:
37
 
@@ -68,14 +68,15 @@ with gr.Blocks() as demo:
68
  with gr.Tab("Image Captioning"):
69
  with gr.Row():
70
  with gr.Column(variant="panel"):
71
- im_cap = gr.Image(interactive=False).style(height=height)
 
72
  with gr.Row():
73
  get_btn_cap = gr.Button("Get Random Image").style(full_width=False)
74
  caption_btn = gr.Button("Create Caption").style(full_width=False)
75
- caption = gr.Text()
76
  get_btn_cap.click(fn=rand_image, outputs=im_cap)
77
  #im_cap.change(generate_text, inputs=im_cap, outputs=caption)
78
- caption_btn.click(generate_text, inputs=im_cap, outputs=caption)
79
 
80
  demo.queue()
81
  demo.launch()
 
30
  return text.split(",")
31
 
32
  get_caption = gr.load("ryaalbr/caption", src="spaces", hf_token=environ["api_key"])
33
+ def generate_text(image, model_name):
34
+ return get_caption(image, model_name)
35
 
36
  with gr.Blocks() as demo:
37
 
 
68
  with gr.Tab("Image Captioning"):
69
  with gr.Row():
70
  with gr.Column(variant="panel"):
71
+ im_cap = gr.Image(interactive=False, type='filepath').style(height=height)
72
+ model_name = gr.Radio(choices=["COCO","Conceptual captions"], type="value", value="COCO", label="Model")
73
  with gr.Row():
74
  get_btn_cap = gr.Button("Get Random Image").style(full_width=False)
75
  caption_btn = gr.Button("Create Caption").style(full_width=False)
76
+ caption = gr.Textbox(label='Caption')
77
  get_btn_cap.click(fn=rand_image, outputs=im_cap)
78
  #im_cap.change(generate_text, inputs=im_cap, outputs=caption)
79
+ caption_btn.click(generate_text, inputs=[im_cap, model_name], outputs=caption)
80
 
81
  demo.queue()
82
  demo.launch()