VaneshDev commited on
Commit
e5cae80
·
verified ·
1 Parent(s): 91f8060

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -2
app.py CHANGED
@@ -1,7 +1,8 @@
1
- import gradio as gr
2
  from PIL import Image
3
  import torch
4
  from torchvision import models, transforms
 
5
  import logging
6
  import os
7
 
@@ -108,10 +109,34 @@ def predict_xray(image):
108
  logger.error(f"Error in prediction: {e}")
109
  return f"Error: {str(e)}"
110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  # Gradio interface
112
  def create_interface():
113
  with gr.Blocks() as demo:
114
- gr.Markdown("<h1 style='text-align:center;'>🩻 RadiologyScan AI</h1><p style='text-align:center;'>AI-powered X-ray Analysis</p>")
115
 
116
  with gr.Tabs():
117
  with gr.TabItem("X-ray Analysis"):
@@ -121,6 +146,13 @@ def create_interface():
121
  gr.Button("Analyze X-ray", elem_id="analyze_button", scale=0.3).click(predict_xray, inputs=img_input, outputs=summary_output)
122
  gr.Button("Clear", elem_id="clear_button", scale=0.3).click(lambda: [None, ""], inputs=None, outputs=[img_input, summary_output])
123
 
 
 
 
 
 
 
 
124
  return demo
125
 
126
  if __name__ == "__main__":
 
1
+ =import gradio as gr
2
  from PIL import Image
3
  import torch
4
  from torchvision import models, transforms
5
+ import fitz # PyMuPDF
6
  import logging
7
  import os
8
 
 
109
  logger.error(f"Error in prediction: {e}")
110
  return f"Error: {str(e)}"
111
 
112
+ # Analyze PDF report
113
+ def analyze_report(file):
114
+ if not file or not file.name.endswith(".pdf"):
115
+ return "Please upload a valid PDF file."
116
+ try:
117
+ doc = fitz.open(file.name)
118
+ text = "".join(page.get_text() for page in doc)
119
+ doc.close()
120
+
121
+ condition, disease, status = "Unclear", "Unknown", "Pending"
122
+
123
+ if "stroke" in text.lower():
124
+ condition, disease, status = "Stroke", "Brain Disorder", "Urgent Care Needed"
125
+ elif "cancer" in text.lower():
126
+ condition, disease, status = "Cancer", "Malignant Growth", "Consult Oncologist"
127
+ elif "fracture" in text.lower():
128
+ condition, disease, status = "Fracture", "Bone Injury", "Orthopedic Attention Required"
129
+
130
+ preview = text[:300] + "..." if text else "No readable content."
131
+ return f"Condition: {condition}\nDisease: {disease}\nStatus: {status}\n\nPreview:\n{preview}"
132
+
133
+ except Exception as e:
134
+ return f"Failed to process PDF: {str(e)}"
135
+
136
  # Gradio interface
137
  def create_interface():
138
  with gr.Blocks() as demo:
139
+ gr.Markdown("<h1 style='text-align:center;'>🩻 RadiologyScan AI</h1><p style='text-align:center;'>AI-powered X-ray and Report Analysis</p>")
140
 
141
  with gr.Tabs():
142
  with gr.TabItem("X-ray Analysis"):
 
146
  gr.Button("Analyze X-ray", elem_id="analyze_button", scale=0.3).click(predict_xray, inputs=img_input, outputs=summary_output)
147
  gr.Button("Clear", elem_id="clear_button", scale=0.3).click(lambda: [None, ""], inputs=None, outputs=[img_input, summary_output])
148
 
149
+ with gr.TabItem("Report Analysis"):
150
+ pdf_input = gr.File(label="Upload PDF Report", file_types=[".pdf"])
151
+ summary_output_report = gr.Textbox(label="Summary Result", lines=5)
152
+ with gr.Row():
153
+ gr.Button("Analyze Report", elem_id="analyze_button", scale=0.3).click(analyze_report, inputs=pdf_input, outputs=summary_output_report)
154
+ gr.Button("Clear", elem_id="clear_button", scale=0.3).click(lambda: [None, ""], inputs=None, outputs=[pdf_input, summary_output_report])
155
+
156
  return demo
157
 
158
  if __name__ == "__main__":