File size: 1,874 Bytes
3b6ded8 2323b4d 2c837a7 2323b4d 3b6ded8 2323b4d 2c837a7 2323b4d 3b6ded8 2323b4d 3b6ded8 03fd523 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 2323b4d 3b6ded8 03fd523 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import gradio as gr
from local_model import query_local
from remote_model import query_remote, client
import time
def query(image, question, model_name):
if model_name == "Local":
return query_local(image, question)
elif model_name == "Remote":
return query_remote(image, question, client)
return "No model selected"
custom_css = """
.output-card {
background-color: #f9fafb;
border: 10px solid #e5e7eb;
border-radius: 8px;
padding: 40px;
}
"""
with gr.Blocks(theme=gr.themes.Soft(), title="Qwen2-VL Analyst") as app:
start_time = time.time()
gr.Markdown(
r"""
¯\_(ツ)_/¯ Intelligence: Upload an image and ask a question
"""
)
with gr.Row():
with gr.Column(scale=1):
img_input = gr.Image(type="pil", label="Upload Image", height=400)
q_input = gr.Textbox(label="Question", lines=2)
with gr.Row():
clear_btn = gr.Button("Clear", variant="secondary")
submit_btn = gr.Button("Analyze Image", variant="primary")
with gr.Column(scale=1):
with gr.Row():
model_dropdown = gr.Dropdown(
label="Select Model", choices=["Local", "Remote"], value="Local"
)
gr.Markdown("Model Analysis:")
with gr.Group(elem_classes="output-card"):
output_box = gr.Markdown(value="Results...", line_breaks=True)
submit_btn.click(
fn=query, inputs=[img_input, q_input, model_dropdown], outputs=output_box
)
q_input.submit(
fn=query, inputs=[img_input, q_input, model_dropdown], outputs=output_box
)
def clear_inputs():
return None, "", ""
clear_btn.click(
fn=clear_inputs, inputs=[], outputs=[img_input, q_input, output_box]
)
app.launch()
|