Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -50,16 +50,16 @@ def rescale_bounding_boxes(bounding_boxes, original_width, original_height, scal
|
|
50 |
|
51 |
|
52 |
@spaces.GPU
|
53 |
-
def run_example(image, text_input,
|
54 |
model = models[model_id].eval()
|
55 |
processor = processors[model_id]
|
56 |
-
|
57 |
messages = [
|
58 |
{
|
59 |
"role": "user",
|
60 |
"content": [
|
61 |
{"type": "image", "image": f"data:image;base64,{image_to_base64(image)}"},
|
62 |
-
{"type": "text", "text":
|
63 |
],
|
64 |
}
|
65 |
]
|
@@ -108,8 +108,6 @@ css = """
|
|
108 |
border: 1px solid #ccc;
|
109 |
}
|
110 |
"""
|
111 |
-
default_system_prompt = ""
|
112 |
-
|
113 |
with gr.Blocks(css=css) as demo:
|
114 |
gr.Markdown(
|
115 |
"""
|
@@ -120,7 +118,6 @@ with gr.Blocks(css=css) as demo:
|
|
120 |
with gr.Column():
|
121 |
input_img = gr.Image(label="Input Image", type="pil")
|
122 |
model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="OS-Copilot/OS-Atlas-Base-7B")
|
123 |
-
system_prompt = gr.Textbox(label="System Prompt", value=default_system_prompt)
|
124 |
text_input = gr.Textbox(label="User Prompt")
|
125 |
submit_btn = gr.Button(value="Submit")
|
126 |
with gr.Column():
|
@@ -130,17 +127,15 @@ with gr.Blocks(css=css) as demo:
|
|
130 |
|
131 |
gr.Examples(
|
132 |
examples=[
|
133 |
-
["assets/
|
134 |
-
["assets/image2.jpg", "detect blue button", default_system_prompt],
|
135 |
-
["assets/image3.jpg", "detect person on bike", default_system_prompt],
|
136 |
],
|
137 |
-
inputs=[input_img, text_input
|
138 |
outputs=[model_output_text, parsed_boxes, annotated_image],
|
139 |
fn=run_example,
|
140 |
cache_examples=True,
|
141 |
label="Try examples"
|
142 |
)
|
143 |
|
144 |
-
submit_btn.click(run_example, [input_img, text_input,
|
145 |
|
146 |
demo.launch(debug=True)
|
|
|
50 |
|
51 |
|
52 |
@spaces.GPU
|
53 |
+
def run_example(image, text_input, model_id="OS-Copilot/OS-Atlas-Base-7B"):
|
54 |
model = models[model_id].eval()
|
55 |
processor = processors[model_id]
|
56 |
+
prompt = f"In this UI screenshot, what is the position of the element corresponding to the command \"{text_input}\" (with bbox)?"
|
57 |
messages = [
|
58 |
{
|
59 |
"role": "user",
|
60 |
"content": [
|
61 |
{"type": "image", "image": f"data:image;base64,{image_to_base64(image)}"},
|
62 |
+
{"type": "text", "text": prompt},
|
63 |
],
|
64 |
}
|
65 |
]
|
|
|
108 |
border: 1px solid #ccc;
|
109 |
}
|
110 |
"""
|
|
|
|
|
111 |
with gr.Blocks(css=css) as demo:
|
112 |
gr.Markdown(
|
113 |
"""
|
|
|
118 |
with gr.Column():
|
119 |
input_img = gr.Image(label="Input Image", type="pil")
|
120 |
model_selector = gr.Dropdown(choices=list(models.keys()), label="Model", value="OS-Copilot/OS-Atlas-Base-7B")
|
|
|
121 |
text_input = gr.Textbox(label="User Prompt")
|
122 |
submit_btn = gr.Button(value="Submit")
|
123 |
with gr.Column():
|
|
|
127 |
|
128 |
gr.Examples(
|
129 |
examples=[
|
130 |
+
["assets/web_6f93090a-81f6-489e-bb35-1a2838b18c01.png", "select search textfield"],
|
|
|
|
|
131 |
],
|
132 |
+
inputs=[input_img, text_input],
|
133 |
outputs=[model_output_text, parsed_boxes, annotated_image],
|
134 |
fn=run_example,
|
135 |
cache_examples=True,
|
136 |
label="Try examples"
|
137 |
)
|
138 |
|
139 |
+
submit_btn.click(run_example, [input_img, text_input, model_selector], [model_output_text, parsed_boxes, annotated_image])
|
140 |
|
141 |
demo.launch(debug=True)
|