jrfish commited on
Commit
cfc9fb5
·
verified ·
1 Parent(s): 38f5514

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -3
app.py CHANGED
@@ -24,12 +24,14 @@ def run_vlm(image, prompt):
24
  return processor.decode(out[0], skip_special_tokens=True)
25
  # return f"Model output for: '{prompt}' and selected image."
26
 
27
- def get_random_image():
28
  jpgs = [f for f in os.listdir(IMAGE_FOLDER) if f.endswith(".jpg")]
29
  if not jpgs:
30
  return STATIC_IMAGE_PATH, STATIC_IMAGE_PATH
31
  selected = os.path.join(IMAGE_FOLDER, random.choice(jpgs))
32
- return selected, selected
 
 
33
 
34
  def process(image_path, user_prompt):
35
  image = Image.open(image_path)
@@ -48,7 +50,7 @@ with gr.Blocks() as demo:
48
 
49
  output = gr.Textbox(label="Model Output")
50
 
51
- random_button.click(fn=get_random_image, outputs=[image_display, image_path])
52
  run_button.click(fn=process, inputs=[image_path, user_prompt], outputs=output)
53
 
54
  # with gr.Blocks() as demo:
 
24
  return processor.decode(out[0], skip_special_tokens=True)
25
  # return f"Model output for: '{prompt}' and selected image."
26
 
27
+ def get_random_image(event):
28
  jpgs = [f for f in os.listdir(IMAGE_FOLDER) if f.endswith(".jpg")]
29
  if not jpgs:
30
  return STATIC_IMAGE_PATH, STATIC_IMAGE_PATH
31
  selected = os.path.join(IMAGE_FOLDER, random.choice(jpgs))
32
+ return gr.update(value=selected)
33
+
34
+
35
 
36
  def process(image_path, user_prompt):
37
  image = Image.open(image_path)
 
50
 
51
  output = gr.Textbox(label="Model Output")
52
 
53
+ random_button.click(fn=get_random_image, outputs=image_display)
54
  run_button.click(fn=process, inputs=[image_path, user_prompt], outputs=output)
55
 
56
  # with gr.Blocks() as demo: