Spaces:
Sleeping
Sleeping
Refactor chatbot structure: update Dockerfile, enhance .gitignore, implement conversation and message models, and integrate CMS service for dynamic responses.
8357353 Download app/database.py from awaiskhancpp/chat-bot: direct link, hf CLI and curl.
- Browser
- Download file 642 Bytes
-
https://huggingface.co/spaces/awaiskhancpp/chat-bot/resolve/main/app/database.py
- Command line
-
hf download hf://spaces/awaiskhancpp/chat-bot/app/database.py
-
curl -L -o database.py https://huggingface.co/spaces/awaiskhancpp/chat-bot/resolve/main/app/database.py
642 Bytes
| from sqlalchemy import create_engine | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| DATABASE_URL = os.getenv("DATABASE_URL") | |
| if not DATABASE_URL: | |
| raise RuntimeError("DATABASE_URL environment variable is not set.") | |
| engine = create_engine( | |
| DATABASE_URL, | |
| pool_pre_ping=True, | |
| pool_recycle=300, | |
| pool_size=5, | |
| max_overflow=10, | |
| ) | |
| SessionLocal = sessionmaker( | |
| autocommit=False, | |
| autoflush=False, | |
| bind=engine | |
| ) | |
| Base = declarative_base() | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() |