Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,8 @@ Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder
|
|
20 |
|
21 |
device = "cuda"
|
22 |
dtype = torch.float16
|
|
|
|
|
23 |
|
24 |
processor = AutoProcessor.from_pretrained("StanfordAIMI/CheXagent-8b", trust_remote_code=True)
|
25 |
generation_config = GenerationConfig.from_pretrained("StanfordAIMI/CheXagent-8b")
|
@@ -41,13 +43,12 @@ def generate(image, prompt):
|
|
41 |
|
42 |
with gr.Blocks() as demo:
|
43 |
gr.Markdown(title)
|
44 |
-
|
45 |
-
with gr.Accordion("Custom Prompt Analysis"):
|
46 |
with gr.Row():
|
47 |
image_input_custom = gr.Image(type="pil")
|
48 |
prompt_input_custom = gr.Textbox(label="Enter your custom prompt")
|
49 |
-
|
50 |
-
|
51 |
|
52 |
def custom_generate(image, prompt):
|
53 |
if isinstance(image, str) and os.path.exists(image):
|
@@ -57,18 +58,24 @@ with gr.Blocks() as demo:
|
|
57 |
return generate(image, prompt)
|
58 |
|
59 |
generate_button_custom.click(fn=custom_generate, inputs=[image_input_custom, prompt_input_custom], outputs=output_text_custom)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
cache_examples=True
|
69 |
-
)
|
70 |
|
71 |
-
with gr.Accordion("Anatomical Feature Analysis"):
|
72 |
anatomies = [
|
73 |
"Airway", "Breathing", "Cardiac", "Diaphragm",
|
74 |
"Everything else (e.g., mediastinal contours, bones, soft tissues, tubes, valves, and pacemakers)"
|
@@ -79,8 +86,20 @@ with gr.Blocks() as demo:
|
|
79 |
generate_button_feature = gr.Button("Analyze Feature")
|
80 |
output_text_feature = gr.Textbox(label="Response")
|
81 |
generate_button_feature.click(fn=lambda image, feature: generate(image, f'Describe "{feature}"'), inputs=[image_input_feature, prompt_select], outputs=output_text_feature)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
-
with gr.Accordion("Common Abnormalities Analysis"):
|
84 |
common_abnormalities = ["Lung Nodule", "Pleural Effusion", "Pneumonia"]
|
85 |
with gr.Row():
|
86 |
image_input_abnormality = gr.Image(type="pil")
|
@@ -88,5 +107,16 @@ with gr.Blocks() as demo:
|
|
88 |
generate_button_abnormality = gr.Button("Analyze Abnormality")
|
89 |
output_text_abnormality = gr.Textbox(label="Response")
|
90 |
generate_button_abnormality.click(fn=lambda image, abnormality: generate(image, f'Analyze for "{abnormality}"'), inputs=[image_input_abnormality, abnormality_select], outputs=output_text_abnormality)
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
demo.launch()
|
|
|
20 |
|
21 |
device = "cuda"
|
22 |
dtype = torch.float16
|
23 |
+
example_images = ["00000174_003.png", "00006596_000.png", "00006663_000.png",
|
24 |
+
"00012976_002.png", "00018401_000.png", "00019799_000.png"]
|
25 |
|
26 |
processor = AutoProcessor.from_pretrained("StanfordAIMI/CheXagent-8b", trust_remote_code=True)
|
27 |
generation_config = GenerationConfig.from_pretrained("StanfordAIMI/CheXagent-8b")
|
|
|
43 |
|
44 |
with gr.Blocks() as demo:
|
45 |
gr.Markdown(title)
|
46 |
+
with gr.Accordion("Custom Prompt Analysis", open=False):
|
|
|
47 |
with gr.Row():
|
48 |
image_input_custom = gr.Image(type="pil")
|
49 |
prompt_input_custom = gr.Textbox(label="Enter your custom prompt")
|
50 |
+
generate_button_custom = gr.Button("Generate")
|
51 |
+
output_text_custom = gr.Textbox(label="Response")
|
52 |
|
53 |
def custom_generate(image, prompt):
|
54 |
if isinstance(image, str) and os.path.exists(image):
|
|
|
58 |
return generate(image, prompt)
|
59 |
|
60 |
generate_button_custom.click(fn=custom_generate, inputs=[image_input_custom, prompt_input_custom], outputs=output_text_custom)
|
61 |
+
custom_prompt_examples = [
|
62 |
+
[os.path.join(os.path.dirname(__file__), img), "You are an expert X-Ray Analyst, describe this chest x-ray in detail focussing on the lung condition:"]
|
63 |
+
for img in example_images
|
64 |
+
]
|
65 |
+
|
66 |
+
# example_prompt = "65 y/m Chronic cough and weight loss x 6 months. Chest X-rays normal. Consulted multiple pulmonologists with not much benefit. One wise pulmonologist thinks of GERD and sends him to the Gastro department. Can you name the classical finding here?"
|
67 |
+
# example_image_path = os.path.join(os.path.dirname(__file__), "hegde.jpg")
|
68 |
+
with gr.Accordion("Examples", open=False):
|
69 |
|
70 |
+
gr.Examples(
|
71 |
+
examples=custom_prompt_examples,
|
72 |
+
inputs=[image_input_custom, prompt_input_custom],
|
73 |
+
outputs=[output_text_custom],
|
74 |
+
fn=custom_generate,
|
75 |
+
cache_examples=True
|
76 |
+
)
|
|
|
|
|
77 |
|
78 |
+
with gr.Accordion("Anatomical Feature Analysis", open=False):
|
79 |
anatomies = [
|
80 |
"Airway", "Breathing", "Cardiac", "Diaphragm",
|
81 |
"Everything else (e.g., mediastinal contours, bones, soft tissues, tubes, valves, and pacemakers)"
|
|
|
86 |
generate_button_feature = gr.Button("Analyze Feature")
|
87 |
output_text_feature = gr.Textbox(label="Response")
|
88 |
generate_button_feature.click(fn=lambda image, feature: generate(image, f'Describe "{feature}"'), inputs=[image_input_feature, prompt_select], outputs=output_text_feature)
|
89 |
+
anatomical_feature_examples = [
|
90 |
+
[os.path.join(os.path.dirname(__file__), img), "Airway"]
|
91 |
+
for img in example_images
|
92 |
+
]
|
93 |
+
with gr.Accordion("Examples", open=False):
|
94 |
+
gr.Examples(
|
95 |
+
examples=anatomical_feature_examples,
|
96 |
+
inputs=[image_input_feature, prompt_select],
|
97 |
+
outputs=[output_text_feature],
|
98 |
+
fn=lambda image, feature: generate(image, f'Describe "{feature}"'),
|
99 |
+
cache_examples=True
|
100 |
+
)
|
101 |
|
102 |
+
with gr.Accordion("Common Abnormalities Analysis", open=False):
|
103 |
common_abnormalities = ["Lung Nodule", "Pleural Effusion", "Pneumonia"]
|
104 |
with gr.Row():
|
105 |
image_input_abnormality = gr.Image(type="pil")
|
|
|
107 |
generate_button_abnormality = gr.Button("Analyze Abnormality")
|
108 |
output_text_abnormality = gr.Textbox(label="Response")
|
109 |
generate_button_abnormality.click(fn=lambda image, abnormality: generate(image, f'Analyze for "{abnormality}"'), inputs=[image_input_abnormality, abnormality_select], outputs=output_text_abnormality)
|
110 |
+
common_abnormalities_examples = [
|
111 |
+
[os.path.join(os.path.dirname(__file__), img), "Lung Nodule"]
|
112 |
+
for img in example_images
|
113 |
+
]
|
114 |
+
with gr.Accordion("Examples", open=False):
|
115 |
+
gr.Examples(
|
116 |
+
examples=common_abnormalities_examples,
|
117 |
+
inputs=[image_input_abnormality, abnormality_select],
|
118 |
+
outputs=[output_text_abnormality],
|
119 |
+
fn=lambda image, abnormality: generate(image, f'Analyze for "{abnormality}"'),
|
120 |
+
cache_examples=True
|
121 |
+
)
|
122 |
demo.launch()
|