ui
Browse files
app.py
CHANGED
@@ -114,19 +114,6 @@ def merge_nearby_rectangles(rectangles, nearness):
|
|
114 |
|
115 |
def run_detection(input_image):
|
116 |
|
117 |
-
""""
|
118 |
-
init_image = input_image.convert("RGB")
|
119 |
-
original_size = init_image.size
|
120 |
-
|
121 |
-
_, image_tensor = image_transform_grounding(init_image)
|
122 |
-
image_pil: Image = image_transform_grounding_for_vis(init_image)
|
123 |
-
|
124 |
-
# run grounidng
|
125 |
-
boxes, logits, phrases = predict(model, image_tensor, grounding_caption, box_threshold, text_threshold, device='cpu')
|
126 |
-
annotated_frame = annotate(image_source=np.asarray(image_pil), boxes=boxes, logits=logits, phrases=phrases)
|
127 |
-
image_with_box = Image.fromarray(cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB))
|
128 |
-
"""
|
129 |
-
|
130 |
# inputimage is PIL as RGB
|
131 |
image = np.asarray(input_image.convert("RGB"))
|
132 |
|
@@ -160,32 +147,21 @@ if __name__ == "__main__":
|
|
160 |
with gr.Row():
|
161 |
with gr.Column():
|
162 |
input_image = gr.Image(source='upload', type="pil")
|
163 |
-
grounding_caption = gr.Textbox(label="Detection Prompt")
|
164 |
run_button = gr.Button(label="Run")
|
165 |
-
|
166 |
-
|
167 |
-
label="Box Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001
|
168 |
-
)
|
169 |
-
text_threshold = gr.Slider(
|
170 |
-
label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.001
|
171 |
-
)
|
172 |
|
173 |
with gr.Column():
|
174 |
-
gallery = gr.outputs.Image(
|
175 |
-
type="pil",
|
176 |
-
# label="grounding results"
|
177 |
-
).style(full_width=True, full_height=True)
|
178 |
-
# gallery = gr.Gallery(label="Generated images", show_label=False).style(
|
179 |
-
# grid=[1], height="auto", container=True, full_width=True, full_height=True)
|
180 |
|
181 |
run_button.click(fn=run_detection, inputs=[
|
182 |
input_image], outputs=[gallery])
|
183 |
gr.Examples(
|
184 |
-
[["Sample1.jpg"
|
185 |
inputs = [input_image],
|
186 |
outputs = [gallery],
|
187 |
fn=run_detection,
|
188 |
cache_examples=True,
|
189 |
-
label='Try
|
190 |
)
|
191 |
block.launch(share=False, show_api=False, show_error=True)
|
|
|
114 |
|
115 |
def run_detection(input_image):
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
# inputimage is PIL as RGB
|
118 |
image = np.asarray(input_image.convert("RGB"))
|
119 |
|
|
|
147 |
with gr.Row():
|
148 |
with gr.Column():
|
149 |
input_image = gr.Image(source='upload', type="pil")
|
|
|
150 |
run_button = gr.Button(label="Run")
|
151 |
+
info = gr.Textbox(label="Info")
|
152 |
+
|
|
|
|
|
|
|
|
|
|
|
153 |
|
154 |
with gr.Column():
|
155 |
+
gallery = gr.outputs.Image(type="pil").style(full_width=True, full_height=True)
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
run_button.click(fn=run_detection, inputs=[
|
158 |
input_image], outputs=[gallery])
|
159 |
gr.Examples(
|
160 |
+
[["Sample1.jpg"],["Sample2.jpg"]],
|
161 |
inputs = [input_image],
|
162 |
outputs = [gallery],
|
163 |
fn=run_detection,
|
164 |
cache_examples=True,
|
165 |
+
label='Try these examples:'
|
166 |
)
|
167 |
block.launch(share=False, show_api=False, show_error=True)
|