Spaces:
Running
Running
Download database.py from HFShishir/leaseguard-api: direct link, hf CLI and curl.
- Browser
- Download file 2.38 kB
-
https://huggingface.co/spaces/HFShishir/leaseguard-api/resolve/main/database.py
- Command line
-
hf download hf://spaces/HFShishir/leaseguard-api/database.py
-
curl -L -o database.py https://huggingface.co/spaces/HFShishir/leaseguard-api/resolve/main/database.py
2.38 kB
| import os | |
| from sqlalchemy import Column, String, Integer, DateTime, JSON, Text, Boolean | |
| from sqlalchemy.ext.declarative import declarative_base | |
| from sqlalchemy.orm import sessionmaker | |
| from sqlalchemy import create_engine | |
| from datetime import datetime, timezone | |
| from config import config | |
| # Database Configuration — Local SQLite | |
| DATABASE_URL = config.LOCAL_DATABASE_URL | |
| engine = create_engine( | |
| DATABASE_URL, | |
| connect_args={"check_same_thread": False} | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| class UserProfile(Base): | |
| __tablename__ = "profiles" | |
| id = Column(String, primary_key=True, index=True) | |
| name = Column(String) | |
| email = Column(String, unique=True, index=True) | |
| hashed_password = Column(String) | |
| plan = Column(String, default="free") | |
| # Credit System | |
| credits = Column(Integer, default=3) | |
| chat_credits = Column(Integer, default=5) | |
| last_credit_reset = Column(DateTime, default=lambda: datetime.now(timezone.utc)) | |
| created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) | |
| class Analysis(Base): | |
| __tablename__ = "analyses" | |
| id = Column(String, primary_key=True, index=True) | |
| user_id = Column(String, index=True) | |
| filename = Column(String) | |
| doc_type = Column(String) | |
| overall_risk = Column(String) | |
| summary = Column(Text) # Encrypted | |
| red_flags = Column(Text) # Encrypted JSON string | |
| positive_clauses = Column(Text) # Encrypted JSON string | |
| # Sharing Features | |
| is_public = Column(Boolean, default=False) | |
| share_token = Column(String, unique=True, index=True, nullable=True) | |
| # Retention Features | |
| renewal_date = Column(String, nullable=True) | |
| reminded = Column(Boolean, default=False) | |
| created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) | |
| class Comparison(Base): | |
| __tablename__ = "comparisons" | |
| id = Column(String, primary_key=True, index=True) | |
| user_id = Column(String, index=True) | |
| filename_a = Column(String) | |
| filename_b = Column(String) | |
| result = Column(JSON) # Stores the ComparisonResult data | |
| created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) | |
| def init_db(): | |
| Base.metadata.create_all(bind=engine) | |
| def get_db(): | |
| db = SessionLocal() | |
| try: | |
| yield db | |
| finally: | |
| db.close() | |