pathananas commited on
Commit
597eed2
·
verified ·
1 Parent(s): b438998

Create database.py

Browse files
Files changed (1) hide show
  1. database.py +23 -0
database.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pymongo import MongoClient
3
+ from datetime import datetime
4
+
5
+ # Get Mongo URI from Hugging Face secret
6
+ MONGO_URI = os.getenv("MONGO_URI")
7
+
8
+ client = MongoClient(MONGO_URI)
9
+ db = client["multimodal_db"]
10
+ collection = db["analysis_history"]
11
+
12
+
13
+ def save_analysis(data):
14
+ data["created_at"] = datetime.utcnow()
15
+ collection.insert_one(data)
16
+
17
+
18
+ def get_history(limit=20):
19
+ return list(collection.find({}, {"_id": 0}).sort("created_at", -1).limit(limit))
20
+
21
+
22
+ def clear_history_db():
23
+ collection.delete_many({})