Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,10 +24,12 @@ 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
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def process(image_path, user_prompt):
|
| 33 |
image = Image.open(image_path)
|
|
@@ -39,9 +41,14 @@ with gr.Blocks() as demo:
|
|
| 39 |
|
| 40 |
image_path = gr.Textbox(value=STATIC_IMAGE_PATH, visible=False)
|
| 41 |
user_prompt = gr.Textbox(label="User Prompt")
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
output = gr.Textbox(label="Model Output")
|
| 44 |
|
|
|
|
| 45 |
run_button.click(fn=process, inputs=[image_path, user_prompt], outputs=output)
|
| 46 |
|
| 47 |
# with gr.Blocks() as demo:
|
|
@@ -58,4 +65,4 @@ with gr.Blocks() as demo:
|
|
| 58 |
# run_button.click(fn=process, inputs=[image_path, user_prompt], outputs=output)
|
| 59 |
|
| 60 |
|
| 61 |
-
demo.launch(
|
|
|
|
| 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)
|
|
|
|
| 41 |
|
| 42 |
image_path = gr.Textbox(value=STATIC_IMAGE_PATH, visible=False)
|
| 43 |
user_prompt = gr.Textbox(label="User Prompt")
|
| 44 |
+
|
| 45 |
+
with gr.Row():
|
| 46 |
+
random_button = gr.Button("Random Photo")
|
| 47 |
+
run_button = gr.Button("Run Model")
|
| 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:
|
|
|
|
| 65 |
# run_button.click(fn=process, inputs=[image_path, user_prompt], outputs=output)
|
| 66 |
|
| 67 |
|
| 68 |
+
demo.launch()
|