Spaces:
Runtime error
Runtime error
Download tests/debug_simple.py from Darshankumarr03/Swift-Query: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/debug_simple.py
- Command line
-
hf download hf://spaces/Darshankumarr03/Swift-Query/tests/debug_simple.py
-
curl -L -o debug_simple.py https://huggingface.co/spaces/Darshankumarr03/Swift-Query/resolve/main/tests/debug_simple.py
1.87 kB
| import os | |
| from flask import Flask | |
| from flask_pymongo import PyMongo | |
| from dotenv import load_dotenv | |
| import logging | |
| load_dotenv() | |
| app = Flask(__name__) | |
| app.config["MONGO_URI"] = os.environ.get("MONGO_URI") | |
| if app.config["MONGO_URI"] and "mongodb.net/?" in app.config["MONGO_URI"]: | |
| app.config['MONGO_URI'] = app.config['MONGO_URI'].replace("mongodb.net/?", "mongodb.net/swiftquery?") | |
| mongo = PyMongo(app) | |
| def run_test(): | |
| with app.app_context(): | |
| user_id = 1 # Simulate user ID 1 | |
| print(f"Testing with user_id: {user_id}") | |
| try: | |
| # 1. Patient Lookup | |
| print("1. Looking up patient...") | |
| patient = mongo.db.patient.find_one({"sql_id": user_id}) | |
| if not patient: | |
| print(" Not found by sql_id, trying id...") | |
| patient = mongo.db.patient.find_one({"id": user_id}) | |
| print(f" Patient Found: {patient.get('name') if patient else 'None'}") | |
| # 2. Chats Lookup | |
| print("2. Looking up chats...") | |
| chats = list(mongo.db.chatsession.find({"patient_id": user_id}).sort("updated_at", -1).limit(5)) | |
| print(f" Found {len(chats)} chats.") | |
| for chat in chats: | |
| print(f" Processing chat {chat.get('id')}") | |
| doctor_id = chat.get('doctor_id') | |
| if doctor_id: | |
| print(f" Doctor ID: {doctor_id}") | |
| doc = mongo.db.doctor.find_one({"$or": [{"sql_id": doctor_id}, {"id": doctor_id}]}) | |
| name = doc.get('name', 'Unknown') if doc else 'Unknown' | |
| print(f" Doctor Name: {name}") | |
| except Exception as e: | |
| print(f"ERROR: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| if __name__ == "__main__": | |
| run_test() | |