|
import gradio as gr |
|
from transformers import AutoModel |
|
from PIL import Image |
|
import torch |
|
import os |
|
|
|
|
|
model = AutoModel.from_pretrained("ECOFRI/CXR-LLAVA-v2", trust_remote_code=True) |
|
model = model.to("cuda" if torch.cuda.is_available() else "cpu") |
|
|
|
|
|
def generate_report(image, api_key): |
|
|
|
if api_key != os.getenv("API_KEY"): |
|
return "Unauthorized access. Invalid API key." |
|
|
|
image = Image.open(image).convert("RGB") |
|
response = model.write_radiologic_report(image) |
|
return response |
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_report, |
|
inputs=[gr.Image(type="filepath", label="Upload Chest X-ray Image"), gr.Textbox(label="API Key")], |
|
outputs=gr.Textbox(label="Radiologic Report"), |
|
title="Chest X-ray Report Generator", |
|
description="Upload a chest X-ray image to generate a radiologic report using the CXR-LLAVA-v2 model." |
|
) |
|
|
|
|
|
interface.launch(share=True) |
|
|