working
Browse files
app.py
CHANGED
|
@@ -2,13 +2,18 @@ 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
|
|
@@ -16,11 +21,11 @@ def generate_report(image):
|
|
| 16 |
# Create the Gradio interface
|
| 17 |
interface = gr.Interface(
|
| 18 |
fn=generate_report,
|
| 19 |
-
inputs=gr.
|
| 20 |
-
outputs=gr.
|
| 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()
|
|
|
|
| 2 |
from transformers import AutoModel
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# Load the model
|
| 8 |
model = AutoModel.from_pretrained("ECOFRI/CXR-LLAVA-v2", trust_remote_code=True)
|
| 9 |
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 10 |
|
| 11 |
# Define the function to generate the report
|
| 12 |
+
def generate_report(image, api_key):
|
| 13 |
+
# Check the API key
|
| 14 |
+
if api_key != os.getenv("API_KEY"):
|
| 15 |
+
return "Unauthorized access. Invalid API key."
|
| 16 |
+
|
| 17 |
image = Image.open(image).convert("RGB")
|
| 18 |
response = model.write_radiologic_report(image)
|
| 19 |
return response
|
|
|
|
| 21 |
# Create the Gradio interface
|
| 22 |
interface = gr.Interface(
|
| 23 |
fn=generate_report,
|
| 24 |
+
inputs=[gr.Image(type="filepath", label="Upload Chest X-ray Image"), gr.Textbox(label="API Key")],
|
| 25 |
+
outputs=gr.Textbox(label="Radiologic Report"),
|
| 26 |
title="Chest X-ray Report Generator",
|
| 27 |
description="Upload a chest X-ray image to generate a radiologic report using the CXR-LLAVA-v2 model."
|
| 28 |
)
|
| 29 |
|
| 30 |
+
# Launch the interface with API enabled
|
| 31 |
+
interface.launch(share=True)
|