Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ from transformers import BlipProcessor, BlipForConditionalGeneration
|
|
| 9 |
# Load your images
|
| 10 |
image_dir = "images"
|
| 11 |
images = [os.path.join(image_dir, f) for f in os.listdir(image_dir) if f.endswith(".jpg")]
|
| 12 |
-
|
| 13 |
# Load the model and processor
|
| 14 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 15 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
@@ -35,16 +35,27 @@ def process(image_path, user_prompt):
|
|
| 35 |
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
with gr.Row():
|
| 38 |
-
image_display = gr.Image(type="filepath", label="Selected Image")
|
| 39 |
-
random_button = gr.Button("Randomize Photo")
|
| 40 |
|
| 41 |
-
image_path = gr.Textbox(visible=False)
|
| 42 |
user_prompt = gr.Textbox(label="User Prompt")
|
| 43 |
run_button = gr.Button("Run Model")
|
| 44 |
output = gr.Textbox(label="Model Output")
|
| 45 |
|
| 46 |
-
random_button.click(fn=random_image, outputs=[image_display, image_path])
|
| 47 |
run_button.click(fn=process, inputs=[image_path, user_prompt], outputs=output)
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
demo.launch()
|
|
|
|
| 9 |
# Load your images
|
| 10 |
image_dir = "images"
|
| 11 |
images = [os.path.join(image_dir, f) for f in os.listdir(image_dir) if f.endswith(".jpg")]
|
| 12 |
+
STATIC_IMAGE_PATH = "images/Places365_val_00000009.jpg"
|
| 13 |
# Load the model and processor
|
| 14 |
processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
|
| 15 |
model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
|
|
|
|
| 35 |
|
| 36 |
with gr.Blocks() as demo:
|
| 37 |
with gr.Row():
|
| 38 |
+
image_display = gr.Image(value=STATIC_IMAGE_PATH, type="filepath", label="Selected Image")
|
|
|
|
| 39 |
|
| 40 |
+
image_path = gr.Textbox(value=STATIC_IMAGE_PATH, visible=False)
|
| 41 |
user_prompt = gr.Textbox(label="User Prompt")
|
| 42 |
run_button = gr.Button("Run Model")
|
| 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:
|
| 48 |
+
# with gr.Row():
|
| 49 |
+
# image_display = gr.Image(type="filepath", label="Selected Image")
|
| 50 |
+
# random_button = gr.Button("Randomize Photo")
|
| 51 |
+
|
| 52 |
+
# image_path = gr.Textbox(visible=False)
|
| 53 |
+
# user_prompt = gr.Textbox(label="User Prompt")
|
| 54 |
+
# run_button = gr.Button("Run Model")
|
| 55 |
+
# output = gr.Textbox(label="Model Output")
|
| 56 |
+
|
| 57 |
+
# random_button.click(fn=random_image, outputs=[image_display, image_path])
|
| 58 |
+
# run_button.click(fn=process, inputs=[image_path, user_prompt], outputs=output)
|
| 59 |
+
|
| 60 |
|
| 61 |
demo.launch()
|