Download src/models.py from CareerAI/app: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/spaces/CareerAI/app/resolve/main/src/models.py
- Command line
-
hf download hf://spaces/CareerAI/app/src/models.py
-
curl -L -o models.py https://huggingface.co/spaces/CareerAI/app/resolve/main/src/models.py
1.71 kB
| import os | |
| from datetime import datetime | |
| from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text, ForeignKey, JSON | |
| from sqlalchemy.orm import declarative_base, sessionmaker, relationship | |
| DB_PATH = os.path.join(os.path.dirname(os.path.dirname(__file__)), "careerai.db") | |
| engine = create_engine(f"sqlite:///{DB_PATH}", connect_args={"check_same_thread": False}) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| class User(Base): | |
| __tablename__ = "users" | |
| id = Column(Integer, primary_key=True, index=True) | |
| email = Column(String, unique=True, index=True, nullable=False) | |
| name = Column(String, nullable=False) | |
| picture = Column(String, nullable=True) | |
| hashed_password = Column(String, nullable=True) | |
| google_id = Column(String, unique=True, index=True, nullable=True) | |
| created_at = Column(DateTime, default=datetime.utcnow) | |
| conversations = relationship("Conversation", back_populates="user", cascade="all, delete-orphan") | |
| class Conversation(Base): | |
| __tablename__ = "conversations" | |
| id = Column(String, primary_key=True, index=True) # UUID string from frontend | |
| user_id = Column(Integer, ForeignKey("users.id"), nullable=False) | |
| title = Column(String, nullable=False) | |
| messages = Column(JSON, nullable=False, default=list) # Store messages as JSON | |
| updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow) | |
| user = relationship("User", back_populates="conversations") | |
| # Create all tables | |
| Base.metadata.create_all(bind=engine) | |
| # Dependency to get DB session | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |