VaneshDev commited on
Commit
525618b
·
verified ·
1 Parent(s): 0efc414

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -84,7 +84,7 @@ def preprocess_image(image):
84
  def predict_xray(image):
85
  try:
86
  if image is None:
87
- return "Please upload an image."
88
 
89
  img_tensor = preprocess_image(image)
90
  with torch.no_grad():
@@ -126,12 +126,12 @@ def predict_xray(image):
126
 
127
  except Exception as e:
128
  logger.error(f"Error in prediction: {e}")
129
- return f"Error: {str(e)}"
130
 
131
  # Analyze PDF report
132
  def analyze_report(file):
133
  if not file or not file.name.endswith(".pdf"):
134
- return "Please upload a valid PDF file."
135
  try:
136
  doc = fitz.open(file.name)
137
  text = "".join(page.get_text() for page in doc)
@@ -147,10 +147,10 @@ def analyze_report(file):
147
  condition, disease, status = "Fracture", "Bone Injury", "Orthopedic Attention Required"
148
 
149
  preview = text[:300] + "..." if text else "No readable content."
150
- return f"Condition: {condition}\nDisease: {disease}\nStatus: {status}\n\nPreview:\n{preview}, <h4>Summary:</h4><p><b>Condition:</b> {condition}</p><p><b>Status:</b> {status}</p>"
151
 
152
  except Exception as e:
153
- return f"Failed to process PDF: {str(e)}"
154
 
155
  # Gradio interface
156
  def create_interface():
@@ -159,9 +159,10 @@ def create_interface():
159
 
160
  with gr.Tabs():
161
  with gr.TabItem("X-ray Analysis"):
162
- img_input = gr.Image(label="Upload Chest X-ray", type="pil")
163
- img_output = gr.HTML()
164
- summary_output = gr.HTML(label="Summary Result")
 
165
  gr.Button("Analyze X-ray").click(predict_xray, inputs=img_input, outputs=[img_output, summary_output])
166
 
167
  with gr.TabItem("Report Analysis"):
 
84
  def predict_xray(image):
85
  try:
86
  if image is None:
87
+ return "Please upload an image.", "Please upload an image."
88
 
89
  img_tensor = preprocess_image(image)
90
  with torch.no_grad():
 
126
 
127
  except Exception as e:
128
  logger.error(f"Error in prediction: {e}")
129
+ return f"Error: {str(e)}", "Error in prediction"
130
 
131
  # Analyze PDF report
132
  def analyze_report(file):
133
  if not file or not file.name.endswith(".pdf"):
134
+ return "Please upload a valid PDF file.", "Please upload a valid PDF file."
135
  try:
136
  doc = fitz.open(file.name)
137
  text = "".join(page.get_text() for page in doc)
 
147
  condition, disease, status = "Fracture", "Bone Injury", "Orthopedic Attention Required"
148
 
149
  preview = text[:300] + "..." if text else "No readable content."
150
+ return f"Condition: {condition}\nDisease: {disease}\nStatus: {status}\n\nPreview:\n{preview}, <h4>Summary:</h4><p><b>Condition:</b> {condition}</p><p><b>Status:</b> {status}</p>", f"Condition: {condition}, Status: {status}"
151
 
152
  except Exception as e:
153
+ return f"Failed to process PDF: {str(e)}", "Failed to process PDF"
154
 
155
  # Gradio interface
156
  def create_interface():
 
159
 
160
  with gr.Tabs():
161
  with gr.TabItem("X-ray Analysis"):
162
+ with gr.Row():
163
+ img_input = gr.Image(label="Upload Chest X-ray", type="pil")
164
+ img_output = gr.HTML()
165
+ summary_output = gr.HTML(label="Summary Result")
166
  gr.Button("Analyze X-ray").click(predict_xray, inputs=img_input, outputs=[img_output, summary_output])
167
 
168
  with gr.TabItem("Report Analysis"):