vikhyatk commited on
Commit
0c5c558
·
verified ·
1 Parent(s): 5442928

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -64
app.py CHANGED
@@ -215,7 +215,7 @@ def localized_query(img, x, y, question):
215
  outline="blue",
216
  )
217
 
218
- yield answer, {"text": "", "entities": []}, gr.update(visible=True, value=img_clone)
219
 
220
 
221
  js = ""
@@ -243,7 +243,7 @@ with gr.Blocks(title="moondream vl (new)", css=css, js=js) as demo:
243
 
244
  gr.Markdown(
245
  """
246
- # 🌔 grounded visual question asnwering
247
  """
248
  )
249
 
@@ -251,72 +251,30 @@ with gr.Blocks(title="moondream vl (new)", css=css, js=js) as demo:
251
 
252
  with gr.Row():
253
  with gr.Column():
254
-
255
- @gr.render(inputs=[mode_radio])
256
- def show_inputs(mode):
257
- with gr.Group():
258
- with gr.Row():
259
- prompt = gr.Textbox(
260
- label="Input",
261
- value="What is this?",
262
- scale=4,
263
- )
264
- submit = gr.Button("Submit")
265
- img = gr.Image(type="pil", label="Upload an Image")
266
- x_slider = gr.Slider(label="x", minimum=0, maximum=1)
267
- y_slider = gr.Slider(label="y", minimum=0, maximum=1)
268
- submit.click(localized_query, [img, x_slider, y_slider, prompt], [output, thought, ann])
269
- prompt.submit(localized_query, [img, x_slider, y_slider, prompt], [output, thought, ann])
270
- x_slider.change(localized_query, [img, x_slider, y_slider, prompt], [output, thought, ann])
271
- y_slider.change(localized_query, [img, x_slider, y_slider, prompt], [output, thought, ann])
272
- img.change(localized_query, [img, x_slider, y_slider, prompt], [output, thought, ann])
273
- def select_handler(image, evt: gr.SelectData):
274
- w, h = img.size
275
- return [evt.index[0] / w, evt.index[1] / h]
276
- img.select(select_handler, img, [x_slider, y_slider])
277
 
278
  with gr.Column():
279
- thought = gr.HighlightedText(
280
- elem_classes=["chain-of-thought"],
281
- label="Thinking tokens",
282
- interactive=False,
283
- )
284
  output = gr.Markdown(label="Response", elem_classes=["output-text"], line_breaks=True)
285
  ann = gr.Image(visible=False)
286
 
287
- def on_select(img, evt: gr.SelectData):
288
- if img is None or evt.value[1] is None:
289
- return gr.update(visible=False, value=None)
290
-
291
- w, h = img.size
292
- if w > 768 or h > 768:
293
- img = Resize(768)(img)
294
- w, h = img.size
295
-
296
- points = json.loads(evt.value[1])
297
-
298
- img_clone = img.copy()
299
- draw = ImageDraw.Draw(img_clone)
300
-
301
- for point in points:
302
- x = int(point[0] * w)
303
- y = int(point[1] * h)
304
- draw.ellipse(
305
- (x - 3, y - 3, x + 3, y + 3),
306
- fill="red",
307
- outline="red",
308
- )
309
-
310
-
311
- return gr.update(visible=True, value=img_clone)
312
-
313
- thought.select(on_select, [input_image], [ann])
314
- input_image.change(lambda: gr.update(visible=False), [], [ann])
315
-
316
- mode_radio.change(
317
- lambda: ("", "", gr.update(visible=False, value=None)),
318
- [],
319
- [output, thought, ann],
320
- )
321
 
322
  demo.queue().launch()
 
215
  outline="blue",
216
  )
217
 
218
+ yield answer, gr.update(visible=True, value=img_clone)
219
 
220
 
221
  js = ""
 
243
 
244
  gr.Markdown(
245
  """
246
+ # 🌔 grounded visual question answering
247
  """
248
  )
249
 
 
251
 
252
  with gr.Row():
253
  with gr.Column():
254
+ with gr.Group():
255
+ with gr.Row():
256
+ prompt = gr.Textbox(
257
+ label="Input",
258
+ value="What is this?",
259
+ scale=4,
260
+ )
261
+ submit = gr.Button("Submit")
262
+ img = gr.Image(type="pil", label="Upload an Image")
263
+ x_slider = gr.Slider(label="x", minimum=0, maximum=1)
264
+ y_slider = gr.Slider(label="y", minimum=0, maximum=1)
265
+ submit.click(localized_query, [img, x_slider, y_slider, prompt], [output, ann])
266
+ prompt.submit(localized_query, [img, x_slider, y_slider, prompt], [output, ann])
267
+ x_slider.change(localized_query, [img, x_slider, y_slider, prompt], [output, ann])
268
+ y_slider.change(localized_query, [img, x_slider, y_slider, prompt], [output, ann])
269
+ img.change(localized_query, [img, x_slider, y_slider, prompt], [output, ann])
270
+ def select_handler(image, evt: gr.SelectData):
271
+ w, h = img.size
272
+ return [evt.index[0] / w, evt.index[1] / h]
273
+ img.select(select_handler, img, [x_slider, y_slider])
 
 
 
274
 
275
  with gr.Column():
 
 
 
 
 
276
  output = gr.Markdown(label="Response", elem_classes=["output-text"], line_breaks=True)
277
  ann = gr.Image(visible=False)
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
 
280
  demo.queue().launch()