Spaces:
Sleeping
Sleeping
| from sqlalchemy import create_engine, Column, Integer, String, Boolean, Float, Text, ForeignKey | |
| from sqlalchemy.orm import sessionmaker, declarative_base | |
| SQLALCHEMY_DATABASE_URL = "sqlite:///./safestream.db" | |
| engine = create_engine( | |
| SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False} | |
| ) | |
| SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) | |
| Base = declarative_base() | |
| class Video(Base): | |
| __tablename__ = "videos" | |
| id = Column(Integer, primary_key=True, index=True) | |
| title = Column(String, index=True) | |
| url = Column(String) # YouTube Embed ID or URL | |
| description = Column(String) | |
| class Comment(Base): | |
| __tablename__ = "comments" | |
| id = Column(Integer, primary_key=True, index=True) | |
| video_id = Column(Integer, ForeignKey("videos.id")) | |
| user = Column(String) | |
| text = Column(Text) | |
| timestamp = Column(String) # ISO format | |
| # Analysis fields | |
| is_toxic = Column(Boolean, default=False) | |
| toxicity_score = Column(Float, default=0.0) | |
| flagged_reason = Column(String, nullable=True) | |
| def init_db(): | |
| Base.metadata.create_all(bind=engine) | |