Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from transformers import
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
-
# Define
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
|
|
|
| 11 |
|
| 12 |
-
# Create
|
| 13 |
-
|
| 14 |
-
fn=
|
| 15 |
-
inputs="
|
| 16 |
-
outputs="
|
| 17 |
-
title="
|
| 18 |
-
description="
|
| 19 |
)
|
| 20 |
|
| 21 |
# Launch the interface
|
| 22 |
-
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModel
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
|
| 6 |
+
# Load the model
|
| 7 |
+
model = AutoModel.from_pretrained("ECOFRI/CXR-LLAVA-v2", trust_remote_code=True)
|
| 8 |
+
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 9 |
|
| 10 |
+
# Define the function to generate the report
|
| 11 |
+
def generate_report(image):
|
| 12 |
+
image = Image.open(image).convert("RGB")
|
| 13 |
+
response = model.write_radiologic_report(image)
|
| 14 |
+
return response
|
| 15 |
|
| 16 |
+
# Create the Gradio interface
|
| 17 |
+
interface = gr.Interface(
|
| 18 |
+
fn=generate_report,
|
| 19 |
+
inputs=gr.inputs.Image(type="file", label="Upload Chest X-ray Image"),
|
| 20 |
+
outputs=gr.outputs.Textbox(label="Radiologic Report"),
|
| 21 |
+
title="Chest X-ray Report Generator",
|
| 22 |
+
description="Upload a chest X-ray image to generate a radiologic report using the CXR-LLAVA-v2 model."
|
| 23 |
)
|
| 24 |
|
| 25 |
# Launch the interface
|
| 26 |
+
interface.launch()
|