Spaces:
Sleeping
Sleeping
Commit
·
fbf538f
1
Parent(s):
5ee40a1
Refactor demo interface in main.py and update .gitignore to exclude cached examples
Browse files- .gitignore +1 -0
- main.py +58 -47
.gitignore
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
.venv
|
| 2 |
__pycache__
|
| 3 |
.pytest_cache
|
|
|
|
|
|
| 1 |
.venv
|
| 2 |
__pycache__
|
| 3 |
.pytest_cache
|
| 4 |
+
gradio_cached_examples
|
main.py
CHANGED
|
@@ -26,53 +26,6 @@ else:
|
|
| 26 |
gr.set_static_paths(["assets"])
|
| 27 |
|
| 28 |
|
| 29 |
-
def run():
|
| 30 |
-
global model
|
| 31 |
-
model = init_model()
|
| 32 |
-
|
| 33 |
-
demo = gr.Interface(
|
| 34 |
-
fn=predict,
|
| 35 |
-
inputs=[
|
| 36 |
-
gr.Image(type="pil", label="Input Image"),
|
| 37 |
-
gr.Textbox(
|
| 38 |
-
label="Prompts",
|
| 39 |
-
placeholder="Enter prompts separated by commas (e.g., neoplastic cells, inflammatory cells)",
|
| 40 |
-
),
|
| 41 |
-
],
|
| 42 |
-
outputs=gr.Image(type="pil", label="Prediction"),
|
| 43 |
-
title="BiomedParse Demo",
|
| 44 |
-
description=description,
|
| 45 |
-
allow_flagging="never",
|
| 46 |
-
examples=[
|
| 47 |
-
["examples/144DME_as_F.jpeg", "edema"],
|
| 48 |
-
["examples/C3_EndoCV2021_00462.jpg", "polyp"],
|
| 49 |
-
["examples/CT-abdomen.png", "liver, pancreas, spleen"],
|
| 50 |
-
["examples/covid_1585.png", "left lung"],
|
| 51 |
-
["examples/covid_1585.png", "right lung"],
|
| 52 |
-
["examples/covid_1585.png", "COVID-19 infection"],
|
| 53 |
-
["examples/ISIC_0015551.jpg", "lesion"],
|
| 54 |
-
["examples/LIDC-IDRI-0140_143_280_CT_lung.png", "lung nodule"],
|
| 55 |
-
["examples/LIDC-IDRI-0140_143_280_CT_lung.png", "COVID-19 infection"],
|
| 56 |
-
[
|
| 57 |
-
"examples/Part_1_516_pathology_breast.png",
|
| 58 |
-
"connective tissue cells",
|
| 59 |
-
],
|
| 60 |
-
[
|
| 61 |
-
"examples/Part_1_516_pathology_breast.png",
|
| 62 |
-
"neoplastic cells",
|
| 63 |
-
],
|
| 64 |
-
[
|
| 65 |
-
"examples/Part_1_516_pathology_breast.png",
|
| 66 |
-
"neoplastic cells, inflammatory cells",
|
| 67 |
-
],
|
| 68 |
-
["examples/T0011.jpg", "optic disc"],
|
| 69 |
-
["examples/T0011.jpg", "optic cup"],
|
| 70 |
-
["examples/TCGA_HT_7856_19950831_8_MRI-FLAIR_brain.png", "glioma"],
|
| 71 |
-
],
|
| 72 |
-
)
|
| 73 |
-
return demo
|
| 74 |
-
|
| 75 |
-
|
| 76 |
description = """Upload a biomedical image and enter prompts (separated by commas) to detect specific features.
|
| 77 |
|
| 78 |
The model understands these prompts:
|
|
@@ -96,6 +49,64 @@ This Space is based on the [BiomedParse model](https://microsoft.github.io/Biome
|
|
| 96 |
"""
|
| 97 |
|
| 98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
demo = run()
|
| 100 |
|
| 101 |
if __name__ == "__main__":
|
|
|
|
| 26 |
gr.set_static_paths(["assets"])
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
description = """Upload a biomedical image and enter prompts (separated by commas) to detect specific features.
|
| 30 |
|
| 31 |
The model understands these prompts:
|
|
|
|
| 49 |
"""
|
| 50 |
|
| 51 |
|
| 52 |
+
examples = [
|
| 53 |
+
["examples/144DME_as_F.jpeg", "edema"],
|
| 54 |
+
["examples/C3_EndoCV2021_00462.jpg", "polyp"],
|
| 55 |
+
["examples/CT-abdomen.png", "liver, pancreas, spleen"],
|
| 56 |
+
["examples/covid_1585.png", "left lung"],
|
| 57 |
+
["examples/covid_1585.png", "right lung"],
|
| 58 |
+
["examples/covid_1585.png", "COVID-19 infection"],
|
| 59 |
+
["examples/ISIC_0015551.jpg", "lesion"],
|
| 60 |
+
["examples/LIDC-IDRI-0140_143_280_CT_lung.png", "lung nodule"],
|
| 61 |
+
["examples/LIDC-IDRI-0140_143_280_CT_lung.png", "COVID-19 infection"],
|
| 62 |
+
["examples/Part_1_516_pathology_breast.png", "connective tissue cells"],
|
| 63 |
+
["examples/Part_1_516_pathology_breast.png", "neoplastic cells"],
|
| 64 |
+
[
|
| 65 |
+
"examples/Part_1_516_pathology_breast.png",
|
| 66 |
+
"neoplastic cells, inflammatory cells",
|
| 67 |
+
],
|
| 68 |
+
["examples/T0011.jpg", "optic disc"],
|
| 69 |
+
["examples/T0011.jpg", "optic cup"],
|
| 70 |
+
["examples/TCGA_HT_7856_19950831_8_MRI-FLAIR_brain.png", "glioma"],
|
| 71 |
+
]
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def run():
|
| 75 |
+
global model
|
| 76 |
+
model = init_model()
|
| 77 |
+
|
| 78 |
+
with gr.Blocks() as demo:
|
| 79 |
+
gr.Markdown("# BiomedParse Demo")
|
| 80 |
+
gr.Markdown(description)
|
| 81 |
+
|
| 82 |
+
with gr.Row():
|
| 83 |
+
with gr.Column():
|
| 84 |
+
input_image = gr.Image(type="pil", label="Input Image")
|
| 85 |
+
input_text = gr.Textbox(
|
| 86 |
+
label="Prompts",
|
| 87 |
+
placeholder="Enter prompts separated by commas (e.g., neoplastic cells, inflammatory cells)",
|
| 88 |
+
)
|
| 89 |
+
with gr.Column():
|
| 90 |
+
output_image = gr.Image(type="pil", label="Prediction")
|
| 91 |
+
|
| 92 |
+
predict_btn = gr.Button("Submit")
|
| 93 |
+
predict_btn.click(
|
| 94 |
+
fn=predict,
|
| 95 |
+
inputs=[input_image, input_text],
|
| 96 |
+
outputs=output_image,
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
gr.Examples(
|
| 100 |
+
examples=examples,
|
| 101 |
+
inputs=[input_image, input_text],
|
| 102 |
+
outputs=output_image,
|
| 103 |
+
fn=predict,
|
| 104 |
+
cache_examples=False,
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
return demo
|
| 108 |
+
|
| 109 |
+
|
| 110 |
demo = run()
|
| 111 |
|
| 112 |
if __name__ == "__main__":
|