Spaces:
Runtime error
Runtime error
Download database.py from pathananas/multimodal-ai-engine: direct link, hf CLI and curl.
- Browser
- Download file 996 Bytes
-
https://huggingface.co/spaces/pathananas/multimodal-ai-engine/resolve/main/database.py
- Command line
-
hf download hf://spaces/pathananas/multimodal-ai-engine/database.py
-
curl -L -o database.py https://huggingface.co/spaces/pathananas/multimodal-ai-engine/resolve/main/database.py
996 Bytes
| import os | |
| from pymongo import MongoClient | |
| from datetime import datetime | |
| # ====================================== | |
| # MongoDB Connection | |
| # ====================================== | |
| MONGO_URI = os.getenv("MONGO_URI", "mongodb://localhost:27017") | |
| client = MongoClient(MONGO_URI) | |
| db = client["multimodal_db"] | |
| analysis_collection = db["analysis_history"] | |
| # ====================================== | |
| # Save Analysis | |
| # ====================================== | |
| def save_analysis(data): | |
| data["created_at"] = datetime.utcnow() | |
| analysis_collection.insert_one(data) | |
| # ====================================== | |
| # Get History | |
| # ====================================== | |
| def get_history(limit=20): | |
| return list( | |
| analysis_collection | |
| .find({}, {"_id": 0}) | |
| .sort("created_at", -1) | |
| .limit(limit) | |
| ) | |
| # ====================================== | |
| # Clear History | |
| # ====================================== | |
| def clear_history_db(): | |
| analysis_collection.delete_many({}) | |
| #comit |