Spaces:
Running
Running
File size: 996 Bytes
74df644 597eed2 d4594a5 597eed2 3ab7835 597eed2 d4594a5 ad6c82f 3ab7835 d4594a5 597eed2 ad6c82f 597eed2 d4594a5 ad6c82f d4594a5 ad6c82f 597eed2 d4594a5 1b0ed82 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 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 |