Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,7 @@ headers = {
|
|
8 |
"x-api-key": os.getenv("JIGSAWSTACK_API_KEY")
|
9 |
}
|
10 |
|
11 |
-
def detect_objects(image_url=None, file_store_key=None, prompts=None, features=None
|
12 |
if not image_url and not file_store_key:
|
13 |
return "β Please provide either an image URL or file store key.", "", "", None
|
14 |
|
@@ -89,7 +89,6 @@ with gr.Blocks() as demo:
|
|
89 |
# Advanced options
|
90 |
prompts = gr.Textbox(label="Prompts (comma-separated)", placeholder="wine glass, bottle, cup", info="Targeted object detection prompts")
|
91 |
features = gr.CheckboxGroup(choices=["object_detection", "gui"], value=["object_detection"], label="Features")
|
92 |
-
annotated_image = gr.Checkbox(label="Return Annotated Image", value=True)
|
93 |
|
94 |
detect_btn = gr.Button("π Detect Objects")
|
95 |
clear_btn = gr.Button("Clear")
|
@@ -98,8 +97,8 @@ with gr.Blocks() as demo:
|
|
98 |
status_box = gr.Textbox(label="Status", interactive=False)
|
99 |
desc_display = gr.Textbox(label="Object Details", lines=10, interactive=False)
|
100 |
|
101 |
-
# Annotated image display
|
102 |
-
annotated_image_display = gr.Image(label="Annotated Image"
|
103 |
|
104 |
json_box = gr.Accordion("Raw JSON Response", open=False)
|
105 |
with json_box:
|
@@ -113,7 +112,7 @@ with gr.Blocks() as demo:
|
|
113 |
|
114 |
input_type.change(fn=toggle_inputs, inputs=input_type, outputs=[image_url, file_store_key])
|
115 |
|
116 |
-
def on_detect(input_mode, url, key, prompts_text, features_list
|
117 |
# Parse prompts
|
118 |
prompts_list = None
|
119 |
if prompts_text.strip():
|
@@ -123,31 +122,24 @@ with gr.Blocks() as demo:
|
|
123 |
return detect_objects(
|
124 |
image_url=url.strip(),
|
125 |
prompts=prompts_list,
|
126 |
-
features=features_list
|
127 |
-
annotated_image=annotated
|
128 |
)
|
129 |
else:
|
130 |
return detect_objects(
|
131 |
file_store_key=key.strip(),
|
132 |
prompts=prompts_list,
|
133 |
-
features=features_list
|
134 |
-
annotated_image=annotated
|
135 |
)
|
136 |
|
137 |
-
def update_annotated_image_visibility(annotated):
|
138 |
-
return gr.update(visible=annotated)
|
139 |
-
|
140 |
detect_btn.click(fn=on_detect, inputs=[
|
141 |
-
input_type, image_url, file_store_key, prompts, features
|
142 |
], outputs=[status_box, desc_display, json_output, annotated_image_display])
|
143 |
|
144 |
-
annotated_image.change(fn=update_annotated_image_visibility, inputs=annotated_image, outputs=annotated_image_display)
|
145 |
-
|
146 |
def clear_all():
|
147 |
-
return "Image URL", "", "", "", "", ["object_detection"],
|
148 |
|
149 |
clear_btn.click(fn=clear_all, inputs=[], outputs=[
|
150 |
-
input_type, image_url, file_store_key, prompts, features,
|
151 |
status_box, desc_display, json_output, annotated_image_display
|
152 |
])
|
153 |
|
|
|
8 |
"x-api-key": os.getenv("JIGSAWSTACK_API_KEY")
|
9 |
}
|
10 |
|
11 |
+
def detect_objects(image_url=None, file_store_key=None, prompts=None, features=None):
|
12 |
if not image_url and not file_store_key:
|
13 |
return "β Please provide either an image URL or file store key.", "", "", None
|
14 |
|
|
|
89 |
# Advanced options
|
90 |
prompts = gr.Textbox(label="Prompts (comma-separated)", placeholder="wine glass, bottle, cup", info="Targeted object detection prompts")
|
91 |
features = gr.CheckboxGroup(choices=["object_detection", "gui"], value=["object_detection"], label="Features")
|
|
|
92 |
|
93 |
detect_btn = gr.Button("π Detect Objects")
|
94 |
clear_btn = gr.Button("Clear")
|
|
|
97 |
status_box = gr.Textbox(label="Status", interactive=False)
|
98 |
desc_display = gr.Textbox(label="Object Details", lines=10, interactive=False)
|
99 |
|
100 |
+
# Annotated image display - always visible
|
101 |
+
annotated_image_display = gr.Image(label="Annotated Image")
|
102 |
|
103 |
json_box = gr.Accordion("Raw JSON Response", open=False)
|
104 |
with json_box:
|
|
|
112 |
|
113 |
input_type.change(fn=toggle_inputs, inputs=input_type, outputs=[image_url, file_store_key])
|
114 |
|
115 |
+
def on_detect(input_mode, url, key, prompts_text, features_list):
|
116 |
# Parse prompts
|
117 |
prompts_list = None
|
118 |
if prompts_text.strip():
|
|
|
122 |
return detect_objects(
|
123 |
image_url=url.strip(),
|
124 |
prompts=prompts_list,
|
125 |
+
features=features_list
|
|
|
126 |
)
|
127 |
else:
|
128 |
return detect_objects(
|
129 |
file_store_key=key.strip(),
|
130 |
prompts=prompts_list,
|
131 |
+
features=features_list
|
|
|
132 |
)
|
133 |
|
|
|
|
|
|
|
134 |
detect_btn.click(fn=on_detect, inputs=[
|
135 |
+
input_type, image_url, file_store_key, prompts, features
|
136 |
], outputs=[status_box, desc_display, json_output, annotated_image_display])
|
137 |
|
|
|
|
|
138 |
def clear_all():
|
139 |
+
return "Image URL", "", "", "", "", ["object_detection"], "", "", "", None
|
140 |
|
141 |
clear_btn.click(fn=clear_all, inputs=[], outputs=[
|
142 |
+
input_type, image_url, file_store_key, prompts, features,
|
143 |
status_box, desc_display, json_output, annotated_image_display
|
144 |
])
|
145 |
|