Arko007 commited on
Commit
103aa6d
·
verified ·
1 Parent(s): 3137d55

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +17 -23
src/streamlit_app.py CHANGED
@@ -527,43 +527,37 @@ Provide a detailed, caring response that helps the patient understand their heal
527
  return {'success': False, 'error': f"Consultation error: {str(e)}"}
528
 
529
  def analyze_medical_report(self, image: Image.Image) -> Dict:
530
- """Analyze medical reports using OCR + Gemini"""
531
  if not self.gemini_model:
532
  return {'success': False, 'error': "Report analysis unavailable"}
533
 
534
  try:
535
- # OCR extraction
536
- text = pytesseract.image_to_string(image)
537
- if not text.strip():
538
- return {'success': False, 'error': "No text found in image"}
 
 
 
 
 
 
 
 
539
 
540
- prompt = f"""You are a medical AI analyzing a healthcare report for Indian patients.
541
-
542
- EXTRACTED REPORT TEXT:
543
- {text}
544
-
545
- ANALYSIS INSTRUCTIONS:
546
- 1. Identify the type of medical report
547
- 2. Highlight values outside normal ranges
548
- 3. Explain abnormal findings in simple terms with analogies
549
- 4. Provide lifestyle recommendations for concerning values
550
- 5. Use markdown formatting for clear structure
551
- 6. Always end with medical disclaimer
552
-
553
- Provide a comprehensive, patient-friendly analysis."""
554
-
555
- response = self.gemini_model.generate_content(prompt)
556
 
557
  return {
558
  'success': True,
559
  'analysis': response.text,
560
- 'extracted_text': text[:500] + "..." if len(text) > 500 else text,
561
  'timestamp': datetime.datetime.now().isoformat()
562
  }
563
 
564
  except Exception as e:
565
  return {'success': False, 'error': f"Analysis error: {str(e)}"}
566
-
567
  def analyze_diabetic_retinopathy(self, image: Image.Image) -> Dict:
568
  """Diabetic retinopathy screening using custom model + Gemini explanation"""
569
  if not self.dr_model_loaded:
 
527
  return {'success': False, 'error': f"Consultation error: {str(e)}"}
528
 
529
  def analyze_medical_report(self, image: Image.Image) -> Dict:
530
+ """Analyze medical reports using Gemini Vision (no OCR needed)"""
531
  if not self.gemini_model:
532
  return {'success': False, 'error': "Report analysis unavailable"}
533
 
534
  try:
535
+ prompt = f"""You are a medical AI analyzing a healthcare report image for Indian patients.
536
+
537
+ ANALYSIS INSTRUCTIONS:
538
+ 1. Identify the type of medical report from the image
539
+ 2. Extract and read all visible text, numbers, and values
540
+ 3. Highlight values outside normal ranges for Indian population
541
+ 4. Explain abnormal findings in simple terms with analogies
542
+ 5. Provide lifestyle recommendations for concerning values
543
+ 6. Use markdown formatting for clear structure
544
+ 7. Always end with medical disclaimer
545
+
546
+ Provide a comprehensive, patient-friendly analysis of this medical report image."""
547
 
548
+ # Use Gemini Vision to analyze image directly
549
+ response = self.gemini_model.generate_content([prompt, image])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
550
 
551
  return {
552
  'success': True,
553
  'analysis': response.text,
554
+ 'extracted_text': "Analysis performed using AI vision - no text extraction needed",
555
  'timestamp': datetime.datetime.now().isoformat()
556
  }
557
 
558
  except Exception as e:
559
  return {'success': False, 'error': f"Analysis error: {str(e)}"}
560
+
561
  def analyze_diabetic_retinopathy(self, image: Image.Image) -> Dict:
562
  """Diabetic retinopathy screening using custom model + Gemini explanation"""
563
  if not self.dr_model_loaded: