Spaces:
Running
on
Zero
Running
on
Zero
derektan
commited on
Commit
·
0b72cc5
1
Parent(s):
1496342
Added more examples
Browse files
app.py
CHANGED
|
@@ -156,15 +156,43 @@ model.eval()
|
|
| 156 |
|
| 157 |
|
| 158 |
# Gradio
|
| 159 |
-
|
| 160 |
[
|
| 161 |
"./imgs/examples/Animalia_Chordata_Aves_Charadriiformes_Laridae_Larus_marinus/80645_39.76079_-74.10316.jpg",
|
| 162 |
-
"Where can I find the shore birds (Animalia Chordata Aves Charadriiformes Laridae Larus marinus) in this image? Please output segmentation mask
|
| 163 |
],
|
| 164 |
[
|
| 165 |
"./imgs/examples/Animalia_Chordata_Mammalia_Rodentia_Caviidae_Hydrochoerus_hydrochaeris/28871_-12.80255_-69.29999.jpg",
|
| 166 |
-
"Where can I find the capybaras (Animalia Chordata Mammalia Rodentia Caviidae Hydrochoerus hydrochaeris) in this image? Please output segmentation mask.",
|
| 167 |
],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
]
|
| 169 |
output_labels = ["Segmentation Output"]
|
| 170 |
|
|
@@ -173,9 +201,7 @@ title = "LISA-AVS: LISA 7B Model Finetuned on AVS-Bench Dataset"
|
|
| 173 |
description = """
|
| 174 |
<font size=4>
|
| 175 |
This is an adapted version of the online demo for <a href='https://github.com/dvlab-research/LISA' target='_blank'>LISA</a>, where we finetune from scratch the LISA model (7B) with data from <a href='https://search-tta.github.io/' target='_blank'>AVS-Bench (Search-TTA)</a>. \n
|
| 176 |
-
**Note**:
|
| 177 |
-
 (a) If multiple users are using it at the same time, they will enter a queue, which may delay some time. \n
|
| 178 |
-
 (b) Different prompts can lead to significantly varied results. Please **standardize** your input text prompts to **avoid ambiguity**, and pay attention to whether the **punctuations** of the input are correct. \n
|
| 179 |
**Usage**: <br>
|
| 180 |
 (1) To let LISA-AVS **segment something**, input prompt like: "Where can I find the <em>Common Name</em> (<em>Full Taxonomy Name</em>) in this image? Please output segmentation mask."; <br>
|
| 181 |
 (2) To let LISA-AVS **output an explanation**, input prompt like: "Where can I find the <em>Common Name</em> (<em>Full Taxonomy Name</em>) in this image? Please output segmentation mask and explain why."; <br>
|
|
@@ -335,22 +361,43 @@ def inference(input_image, input_str):
|
|
| 335 |
return output_image, output_str
|
| 336 |
|
| 337 |
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
gr.
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
demo.queue()
|
| 356 |
demo.launch()
|
|
|
|
| 156 |
|
| 157 |
|
| 158 |
# Gradio
|
| 159 |
+
examples_in_domain = [
|
| 160 |
[
|
| 161 |
"./imgs/examples/Animalia_Chordata_Aves_Charadriiformes_Laridae_Larus_marinus/80645_39.76079_-74.10316.jpg",
|
| 162 |
+
"Where can I find the shore birds (Animalia Chordata Aves Charadriiformes Laridae Larus marinus) in this image? Please output segmentation mask.",
|
| 163 |
],
|
| 164 |
[
|
| 165 |
"./imgs/examples/Animalia_Chordata_Mammalia_Rodentia_Caviidae_Hydrochoerus_hydrochaeris/28871_-12.80255_-69.29999.jpg",
|
| 166 |
+
"Where can I find the capybaras (Animalia Chordata Mammalia Rodentia Caviidae Hydrochoerus hydrochaeris) in this image? Please output segmentation mask and explain why.",
|
| 167 |
],
|
| 168 |
+
[
|
| 169 |
+
"./imgs/examples/Animalia_Arthropoda_Malacostraca_Decapoda_Ocypodidae_Ocypode_quadrata/277303_38.72364_-75.07749.jpg",
|
| 170 |
+
"Where can I find the crabs (Animalia Arthropoda Malacostraca Decapoda Ocypodidae Ocypode quadrata) in this image? Please output segmentation mask.",
|
| 171 |
+
],
|
| 172 |
+
[
|
| 173 |
+
"./imgs/examples/Animalia_Chordata_Mammalia_Rodentia_Sciuridae_Marmota_marmota/388246_45.49036_7.14796.jpg",
|
| 174 |
+
"Where can I find the marmots (Animalia Chordata Mammalia Rodentia Sciuridae Marmota marmota) in this image? Please output segmentation mask and explain why.",
|
| 175 |
+
],
|
| 176 |
+
[
|
| 177 |
+
"./imgs/examples/Animalia_Chordata_Reptilia_Squamata_Varanidae_Varanus_salvator/410613_5.35573_100.28948.jpg",
|
| 178 |
+
"Where can I find monitor lizard (Animalia Chordata Reptilia Squamata Varanidae Varanus salvator) in this image? Please output segmentation mask.",
|
| 179 |
+
],
|
| 180 |
+
|
| 181 |
+
]
|
| 182 |
+
|
| 183 |
+
examples_out_domain = [
|
| 184 |
+
[
|
| 185 |
+
"./imgs/examples/Animalia_Chordata_Mammalia_Carnivora_Phocidae_Mirounga_angustirostris/27423_35.64005_-121.17595.jpg",
|
| 186 |
+
"Where can I find the seals (Animalia Chordata Mammalia Carnivora Phocidae Mirounga angustirostris) in this image? Please output segmentation mask and explain why.",
|
| 187 |
+
],
|
| 188 |
+
[
|
| 189 |
+
"./imgs/examples/Animalia_Chordata_Mammalia_Carnivora_Canidae_Canis_aureus/1528408_13.00422_80.23033.jpg",
|
| 190 |
+
"Where can I find the wolves (Animalia Chordata Mammalia Carnivora Canidae Canis aureus) in this image? Please output segmentation mask.",
|
| 191 |
+
],
|
| 192 |
+
[
|
| 193 |
+
"./imgs/examples/Animalia_Chordata_Mammalia_Carnivora_Canidae_Urocyon_littoralis/304160_34.0144_-119.54417.jpg",
|
| 194 |
+
"Where can I find the raccoons (Animalia Chordata Mammalia Carnivora Canidae Urocyon littoralis) in this image? Please output segmentation mask and explain why.",
|
| 195 |
+
],
|
| 196 |
]
|
| 197 |
output_labels = ["Segmentation Output"]
|
| 198 |
|
|
|
|
| 201 |
description = """
|
| 202 |
<font size=4>
|
| 203 |
This is an adapted version of the online demo for <a href='https://github.com/dvlab-research/LISA' target='_blank'>LISA</a>, where we finetune from scratch the LISA model (7B) with data from <a href='https://search-tta.github.io/' target='_blank'>AVS-Bench (Search-TTA)</a>. \n
|
| 204 |
+
**Note**: Different prompts can lead to significantly varied results. Please **standardize** your input text prompts to **avoid ambiguity**, and pay attention to whether the **punctuations** of the input are correct. \n
|
|
|
|
|
|
|
| 205 |
**Usage**: <br>
|
| 206 |
 (1) To let LISA-AVS **segment something**, input prompt like: "Where can I find the <em>Common Name</em> (<em>Full Taxonomy Name</em>) in this image? Please output segmentation mask."; <br>
|
| 207 |
 (2) To let LISA-AVS **output an explanation**, input prompt like: "Where can I find the <em>Common Name</em> (<em>Full Taxonomy Name</em>) in this image? Please output segmentation mask and explain why."; <br>
|
|
|
|
| 361 |
return output_image, output_str
|
| 362 |
|
| 363 |
|
| 364 |
+
with gr.Blocks() as demo:
|
| 365 |
+
# Title, description and article
|
| 366 |
+
gr.Markdown(f"# {title}")
|
| 367 |
+
gr.Markdown(description)
|
| 368 |
+
# gr.Markdown(articSle)
|
| 369 |
+
|
| 370 |
+
# Input and output columns side-by-side
|
| 371 |
+
with gr.Row():
|
| 372 |
+
with gr.Column(): # Left column – inputs
|
| 373 |
+
inp_image = gr.Image(type="filepath", label="Input Image")
|
| 374 |
+
inp_text = gr.Textbox(lines=1, placeholder=None, label="Text Instruction")
|
| 375 |
+
run_btn = gr.Button("Run", variant="primary")
|
| 376 |
+
with gr.Column(): # Right column – outputs
|
| 377 |
+
out_seg = gr.Image(type="pil", label="Segmentation Output")
|
| 378 |
+
out_text = gr.Textbox(lines=1, label="Text Output")
|
| 379 |
+
|
| 380 |
+
# Bind the button to inference
|
| 381 |
+
run_btn.click(fn=inference, inputs=[inp_image, inp_text], outputs=[out_seg, out_text])
|
| 382 |
+
|
| 383 |
+
# ---------------- Example Galleries ----------------
|
| 384 |
+
gr.Markdown("### In-Domain Taxonomy")
|
| 385 |
+
gr.Examples(
|
| 386 |
+
examples=examples_in_domain,
|
| 387 |
+
inputs=[inp_image, inp_text],
|
| 388 |
+
outputs=[out_seg, out_text],
|
| 389 |
+
fn=inference,
|
| 390 |
+
cache_examples=False,
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
gr.Markdown("### Out-Domain Taxonomy")
|
| 394 |
+
gr.Examples(
|
| 395 |
+
examples=examples_out_domain,
|
| 396 |
+
inputs=[inp_image, inp_text],
|
| 397 |
+
outputs=[out_seg, out_text],
|
| 398 |
+
fn=inference,
|
| 399 |
+
cache_examples=False,
|
| 400 |
+
)
|
| 401 |
|
| 402 |
demo.queue()
|
| 403 |
demo.launch()
|