Update app.py
Browse files
app.py
CHANGED
|
@@ -46,12 +46,12 @@ def describe_image(uploaded_image, model_choice):
|
|
| 46 |
if uploaded_image is None:
|
| 47 |
return "Please upload an image."
|
| 48 |
|
| 49 |
-
if model_choice == "
|
| 50 |
if vision_language_model_base is None:
|
| 51 |
return "Base model failed to load."
|
| 52 |
model = vision_language_model_base
|
| 53 |
processor = vision_language_processor_base
|
| 54 |
-
elif model_choice == "
|
| 55 |
if vision_language_model_large is None:
|
| 56 |
return "Large model failed to load."
|
| 57 |
model = vision_language_model_large
|
|
@@ -89,10 +89,10 @@ if device == "cpu":
|
|
| 89 |
|
| 90 |
# Define examples
|
| 91 |
examples = [
|
| 92 |
-
["images/1.png", "
|
| 93 |
-
["images/1.png", "
|
| 94 |
-
["images/2.png", "
|
| 95 |
-
["images/2.png", "
|
| 96 |
]
|
| 97 |
|
| 98 |
css = """
|
|
@@ -114,15 +114,12 @@ with gr.Blocks(theme="bethecloud/storj_theme", css=css) as demo:
|
|
| 114 |
with gr.Column():
|
| 115 |
image_input = gr.Image(label="Upload Image", type="pil")
|
| 116 |
generate_btn = gr.Button("Generate Caption", elem_classes="submit-btn")
|
|
|
|
| 117 |
# Right column: Model choice, output, and examples
|
| 118 |
with gr.Column():
|
| 119 |
model_choice = gr.Radio(["Base", "Large"], label="Model Choice", value="Base")
|
| 120 |
-
|
| 121 |
with gr.Row():
|
| 122 |
output = gr.Textbox(label="Generated Caption", lines=4, show_copy_button=True)
|
| 123 |
-
|
| 124 |
-
gr.Examples(examples=examples, inputs=[image_input, model_choice])
|
| 125 |
-
|
| 126 |
# Connect the button to the function
|
| 127 |
generate_btn.click(fn=describe_image, inputs=[image_input, model_choice], outputs=output)
|
| 128 |
|
|
|
|
| 46 |
if uploaded_image is None:
|
| 47 |
return "Please upload an image."
|
| 48 |
|
| 49 |
+
if model_choice == "Florence-2-base":
|
| 50 |
if vision_language_model_base is None:
|
| 51 |
return "Base model failed to load."
|
| 52 |
model = vision_language_model_base
|
| 53 |
processor = vision_language_processor_base
|
| 54 |
+
elif model_choice == "Florence-2-large":
|
| 55 |
if vision_language_model_large is None:
|
| 56 |
return "Large model failed to load."
|
| 57 |
model = vision_language_model_large
|
|
|
|
| 89 |
|
| 90 |
# Define examples
|
| 91 |
examples = [
|
| 92 |
+
["images/1.png", "Florence-2-base"],
|
| 93 |
+
["images/1.png", "Florence-2-large"],
|
| 94 |
+
["images/2.png", "Florence-2-base"],
|
| 95 |
+
["images/2.png", "Florence-2-large"]
|
| 96 |
]
|
| 97 |
|
| 98 |
css = """
|
|
|
|
| 114 |
with gr.Column():
|
| 115 |
image_input = gr.Image(label="Upload Image", type="pil")
|
| 116 |
generate_btn = gr.Button("Generate Caption", elem_classes="submit-btn")
|
| 117 |
+
gr.Examples(examples=examples, inputs=[image_input, model_choice])
|
| 118 |
# Right column: Model choice, output, and examples
|
| 119 |
with gr.Column():
|
| 120 |
model_choice = gr.Radio(["Base", "Large"], label="Model Choice", value="Base")
|
|
|
|
| 121 |
with gr.Row():
|
| 122 |
output = gr.Textbox(label="Generated Caption", lines=4, show_copy_button=True)
|
|
|
|
|
|
|
|
|
|
| 123 |
# Connect the button to the function
|
| 124 |
generate_btn.click(fn=describe_image, inputs=[image_input, model_choice], outputs=output)
|
| 125 |
|