ryaalbr commited on
Commit
fbb03a4
1 Parent(s): 54beb65

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -112,14 +112,15 @@ def search(search_query):
112
 
113
 
114
 
115
- with gr.Blocks(css=".caption-text {font-size: 40px !important;}") as demo:
116
 
117
- with gr.Tab("Zero-Shot Classification"):
118
  labels = gr.State([]) # creates hidden component that can store a value and can be used as input/output; here, initial value is an empty list
119
  instructions = """## Instructions:
120
  1. Enter list of labels separated by commas (or select one of the examples below)
121
- 2. Click **Get Random Image** to grab a random image from dataset and analyze it against the labels
122
- 3. Click **Re-Classify Image** to re-run classification on current image after changing labels"""
 
123
  gr.Markdown(instructions)
124
  with gr.Row(variant="compact"):
125
  label_text = gr.Textbox(show_label=False, placeholder="Enter classification labels").style(container=False)
@@ -134,17 +135,23 @@ with gr.Blocks(css=".caption-text {font-size: 40px !important;}") as demo:
134
  im = gr.Image(interactive=False).style(height=height)
135
  with gr.Row():
136
  get_btn = gr.Button("Get Random Image").style(full_width=False)
137
- reclass_btn = gr.Button("Re-Classify Image").style(full_width=False)
138
  cf = gr.Label()
139
  #submit_btn.click(fn=set_labels, inputs=label_text)
140
  label_text.change(fn=set_labels, inputs=label_text, outputs=labels) # parse list if changed
141
  label_text.blur(fn=set_labels, inputs=label_text, outputs=labels) # parse list if focus is moved elsewhere; ensures that list is fully parsed before classification
142
  label_text.submit(fn=set_labels, inputs=label_text, outputs=labels) # parse list if user hits enter; ensures that list is fully parsed before classification
143
  get_btn.click(fn=rand_image, outputs=im)
144
- im.change(predict, inputs=[im, labels], outputs=cf)
145
- reclass_btn.click(predict, inputs=[im, labels], outputs=cf)
146
 
147
- with gr.Tab("Image Captioning"):
 
 
 
 
 
 
148
  with gr.Row():
149
  with gr.Column(variant="panel"):
150
  im_cap = gr.Image(interactive=False, type='filepath').style(height=height)
@@ -157,9 +164,20 @@ with gr.Blocks(css=".caption-text {font-size: 40px !important;}") as demo:
157
  #im_cap.change(generate_text, inputs=im_cap, outputs=caption)
158
  caption_btn.click(generate_text, inputs=[im_cap, model_name], outputs=caption)
159
 
160
- with gr.Tab("Image Search"):
 
 
 
 
 
161
  with gr.Column(variant="panel"):
162
  desc = gr.Textbox(show_label=False, placeholder="Enter description").style(container=False)
 
 
 
 
 
 
163
  search_btn = gr.Button("Find Images").style(full_width=False)
164
  gallery = gr.Gallery(show_label=False).style(grid=(2,2,3,5))
165
  search_btn.click(search,inputs=desc, outputs=gallery, postprocess=False)
 
112
 
113
 
114
 
115
+ with gr.Blocks() as demo:
116
 
117
+ with gr.Tab("Classification"):
118
  labels = gr.State([]) # creates hidden component that can store a value and can be used as input/output; here, initial value is an empty list
119
  instructions = """## Instructions:
120
  1. Enter list of labels separated by commas (or select one of the examples below)
121
+ 2. Click **Get Random Image** to grab a random image from dataset
122
+ 3. Click **Classify Image** to analyze current image against the labels (including after changing labels)
123
+ 4. The dataset (<a href="https://github.com/unsplash/datasets" target="_blank">Unsplash Lite</a>) contains 25,000 nature-focused images."""
124
  gr.Markdown(instructions)
125
  with gr.Row(variant="compact"):
126
  label_text = gr.Textbox(show_label=False, placeholder="Enter classification labels").style(container=False)
 
135
  im = gr.Image(interactive=False).style(height=height)
136
  with gr.Row():
137
  get_btn = gr.Button("Get Random Image").style(full_width=False)
138
+ class_btn = gr.Button("Classify Image").style(full_width=False)
139
  cf = gr.Label()
140
  #submit_btn.click(fn=set_labels, inputs=label_text)
141
  label_text.change(fn=set_labels, inputs=label_text, outputs=labels) # parse list if changed
142
  label_text.blur(fn=set_labels, inputs=label_text, outputs=labels) # parse list if focus is moved elsewhere; ensures that list is fully parsed before classification
143
  label_text.submit(fn=set_labels, inputs=label_text, outputs=labels) # parse list if user hits enter; ensures that list is fully parsed before classification
144
  get_btn.click(fn=rand_image, outputs=im)
145
+ #im.change(predict, inputs=[im, labels], outputs=cf)
146
+ class_btn.click(predict, inputs=[im, labels], outputs=cf)
147
 
148
+ with gr.Tab("Captioning"):
149
+ instructions = """## Instructions:
150
+ 1. Click **Get Random Image** to grab a random image from dataset
151
+ 1. Click **Create Caption** to generate a caption for the image
152
+ 1. Different models can be selected: *COCO* generally produces more straight-forward captions, but it is a smaller dataset and therefore struggles to recognize certain objects; **Conceptual Captions** is a much larger dataset but often generally overly...um...poetic results
153
+ 1. The dataset (<a href="https://github.com/unsplash/datasets" target="_blank">Unsplash Lite</a>) contains 25,000 nature-focused images."""
154
+ gr.Markdown(instructions)
155
  with gr.Row():
156
  with gr.Column(variant="panel"):
157
  im_cap = gr.Image(interactive=False, type='filepath').style(height=height)
 
164
  #im_cap.change(generate_text, inputs=im_cap, outputs=caption)
165
  caption_btn.click(generate_text, inputs=[im_cap, model_name], outputs=caption)
166
 
167
+ with gr.Tab("Search"):
168
+ instructions = """## Instructions:
169
+ 1. Enter a search query (or select one of the examples below)
170
+ 2. Click **Find Images** to find images that match the query (top 5 are shown in order from left to right)
171
+ 3. The dataset (<a href="https://github.com/unsplash/datasets" target="_blank">Unsplash Lite</a>) contains 25,000 nature-focused images."""
172
+ gr.Markdown(instructions)
173
  with gr.Column(variant="panel"):
174
  desc = gr.Textbox(show_label=False, placeholder="Enter description").style(container=False)
175
+ gr.Examples(["someone holding flowers",
176
+ "someone holding blue flowers",
177
+ "red fruit in a person's hands",
178
+ "an aerial view of forest",
179
+ "a waterfall with a rainbow"
180
+ ], inputs=desc)
181
  search_btn = gr.Button("Find Images").style(full_width=False)
182
  gallery = gr.Gallery(show_label=False).style(grid=(2,2,3,5))
183
  search_btn.click(search,inputs=desc, outputs=gallery, postprocess=False)