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())