Spaces:
Sleeping
Sleeping
File size: 1,160 Bytes
32ca500 |
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 |
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)
|