Spaces:
Sleeping
Sleeping
Download tests/test_invalid_image.py from Presight-AI/app: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/Presight-AI/app/resolve/main/tests/test_invalid_image.py
- Command line
-
hf download hf://spaces/Presight-AI/app/tests/test_invalid_image.py
-
curl -L -o test_invalid_image.py https://huggingface.co/spaces/Presight-AI/app/resolve/main/tests/test_invalid_image.py
1.6 kB
| import os | |
| import sys | |
| import asyncio | |
| from unittest.mock import MagicMock, patch | |
| # Add project root to path | |
| sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from backend.gemini_analyzer import GeminiPrescriptionAnalyzer, GeminiPrescription | |
| import pytest | |
| async def test_invalid_image_detection(): | |
| print("🧪 Testing Invalid Image Detection...") | |
| # Mock the Gemini client | |
| mock_response = MagicMock() | |
| mock_response.text = """ | |
| { | |
| "medical_context": { | |
| "is_prescription": false, | |
| "diagnosis": "", | |
| "symptoms": "", | |
| "allergies": "" | |
| }, | |
| "patient_info": {}, | |
| "healthcare_provider": {}, | |
| "prescription_details": {}, | |
| "medicines": [], | |
| "special_instructions": "This image does not appear to be a prescription." | |
| } | |
| """ | |
| with patch('google.generativeai.GenerativeModel') as MockModel: | |
| mock_client = MockModel.return_value | |
| mock_client.generate_content.return_value = mock_response | |
| analyzer = GeminiPrescriptionAnalyzer(api_key="dummy_key") | |
| # Test with dummy text | |
| result = analyzer.analyze_prescription(raw_text="dummy", image_path="dummy.jpg") | |
| print(f"Is Prescription: {result.is_prescription}") | |
| if result.is_prescription is False: | |
| print("✅ Successfully detected invalid image") | |
| else: | |
| print("❌ Failed to detect invalid image") | |
| if __name__ == "__main__": | |
| asyncio.run(test_invalid_image_detection()) | |