Spaces:
Runtime error
Runtime error
Download tests/verify_recording.py from Darshankumarr03/Swift-Query: direct link, hf CLI and curl.
- Browser
- Download file 2.12 kB
-
https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/verify_recording.py
- Command line
-
hf download hf://spaces/Darshankumarr03/Swift-Query/tests/verify_recording.py
-
curl -L -o verify_recording.py https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/verify_recording.py
2.12 kB
| import requests | |
| import os | |
| import sys | |
| # Configuration | |
| BASE_URL = "http://127.0.0.1:8080" | |
| LOGIN_URL = f"{BASE_URL}/login/doctor" | |
| UPLOAD_URL = f"{BASE_URL}/doctor/upload_recording" | |
| HISTORY_URL = f"{BASE_URL}/api/history" | |
| # Dummy Credentials (assumes a doctor exists or we might fail login) | |
| # We will try a known default or just print the result | |
| USERNAME = "Dr. Smith" # Replace with actual if known, or we rely on pre-seeded data | |
| PASSWORD = "password" | |
| def create_dummy_audio(): | |
| with open("test_audio.mp3", "wb") as f: | |
| f.write(os.urandom(1024)) # 1KB random data | |
| def verify(): | |
| session = requests.Session() | |
| # 1. Login | |
| print(f"Logging in as {USERNAME}...") | |
| res = session.post(LOGIN_URL, data={"name": USERNAME, "password": PASSWORD}) | |
| if res.url.endswith("/dashboard"): | |
| print("Login Successful!") | |
| else: | |
| print("Login Failed. URL:", res.url) | |
| # If login fails, we might need to seed a doctor or check DB. | |
| # But let's proceed to see if we can trigger the endpoint (it will 403) | |
| # 2. Upload Recording | |
| print("Uploading recording...") | |
| create_dummy_audio() | |
| try: | |
| with open("test_audio.mp3", "rb") as f: | |
| files = {'audio': ('test_audio.mp3', f, 'audio/mp3')} | |
| data = {'patient_id': '1'} | |
| res = session.post(UPLOAD_URL, files=files, data=data) | |
| print("Upload Response Code:", res.status_code) | |
| try: | |
| print("Upload Response Body:", res.json()) | |
| except: | |
| print("Upload Response Text:", res.text) | |
| except Exception as e: | |
| print(f"Upload failed: {e}") | |
| finally: | |
| if os.path.exists("test_audio.mp3"): | |
| os.remove("test_audio.mp3") | |
| # 3. Check History | |
| print("Checking History...") | |
| res = session.get(HISTORY_URL) | |
| print("History Response Code:", res.status_code) | |
| try: | |
| hist = res.json() | |
| print(f"History Items: {len(hist.get('history', []))}") | |
| # print(hist) | |
| except: | |
| print("History Response Text:", res.text) | |
| if __name__ == "__main__": | |
| verify() | |