app / tests /test_gemini_vision.py
sabareesh4317
Initial deploy (Clean)
e2a1a46
Raw History Blame Contribute Delete
1.46 kB
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())