File size: 1,460 Bytes
e2a1a46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import sys
import asyncio
from pathlib import Path

# Add project root to path
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from backend.gemini_analyzer import GeminiPrescriptionAnalyzer

import pytest

@pytest.mark.asyncio
async def test_vision():
    print("🧪 Testing Gemini Vision Integration...")
    
    # Use the default key from the code or env
    api_key = os.getenv('GEMINI_API_KEY', 'AIzaSyD72bMoC9tuQyz2QZTWEQqaM2TXk4M_wI0')
    
    analyzer = GeminiPrescriptionAnalyzer(api_key=api_key)
    
    image_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "sample_prescriptions", "sample_prescription.jpg")
    
    if not os.path.exists(image_path):
        print(f"❌ Sample image not found at {image_path}")
        return
        
    print(f"📸 Analyzing image: {image_path}")
    
    try:
        # Test with image path
        result = analyzer.analyze_prescription(raw_text="OCR failed", image_path=image_path)
        
        print("\n✅ Analysis Result:")
        print(f"Patient: {result.patient_name}")
        print(f"Medicines: {len(result.medicines)}")
        for med in result.medicines:
            print(f" - {med.name} ({med.strength})")
            
        print(f"\nConfidence: {result.analysis_confidence}")
        
    except Exception as e:
        print(f"❌ Test failed: {e}")

if __name__ == "__main__":
    asyncio.run(test_vision())