Spaces:
Running
Running
File size: 1,244 Bytes
9bc1376 bde447e 9bc1376 2876716 9bc1376 c65c56b 9bc1376 bde447e 9bc1376 bde447e |
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 47 48 49 50 51 |
from pymongo import MongoClient
from core.logger import logger
from core.settings import cnf
import streamlit as st
@st.cache_resource
def get_mongo_client():
try:
uri = cnf.MONGO_URI
dbname = cnf.MONGO_DB
# Check if required environment variables are set
if not uri or not dbname:
logger.warning("MongoDB configuration not found. Running without database.")
return None
client = MongoClient(uri)
db = client[dbname]
db.command("ping")
logger.info("MongoDB connection established successfully")
return db
except Exception as e:
logger.error(f"MongoDB connection failed: {e}")
return None
def get_results_collection():
db = get_mongo_client()
if db is None:
return None
return db["img_gen"]
def get_image_collection():
db = get_mongo_client()
if db is None:
return None
return db["image_analyses"]
def get_video_collection():
db = get_mongo_client()
if db is None:
return None
return db["video_analyses"]
def get_script_collection():
db = get_mongo_client()
if db is None:
return None
return db["script_generation"]
|