jcsagar commited on
Commit
0a32a5c
·
verified ·
1 Parent(s): b83ef84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -1,22 +1,26 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
 
3
 
4
- # Initialize the pipeline
5
- pipe = pipeline("feature-extraction", model="ECOFRI/CXR-LLAVA-v2", trust_remote_code=True)
 
6
 
7
- # Define a function to process inputs and return outputs
8
- def extract_features(text):
9
- features = pipe(text)
10
- return features
 
11
 
12
- # Create a Gradio interface
13
- iface = gr.Interface(
14
- fn=extract_features,
15
- inputs="text",
16
- outputs="json",
17
- title="Feature Extraction Demo",
18
- description="Enter text to extract features using the ECOFRI/CXR-LLAVA-v2 model."
19
  )
20
 
21
  # Launch the interface
22
- iface.launch()
 
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()