Shubhi324 commited on
Commit
32ca500
·
verified ·
1 Parent(s): 31b7ccf

Upload 2 files

Browse files
Files changed (2) hide show
  1. database.py +34 -0
  2. schemas.py +35 -0
database.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sqlalchemy import create_engine, Column, Integer, String, Boolean, Float, Text, ForeignKey
2
+ from sqlalchemy.orm import sessionmaker, declarative_base
3
+
4
+ SQLALCHEMY_DATABASE_URL = "sqlite:///./safestream.db"
5
+
6
+ engine = create_engine(
7
+ SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False}
8
+ )
9
+ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
10
+
11
+ Base = declarative_base()
12
+
13
+ class Video(Base):
14
+ __tablename__ = "videos"
15
+ id = Column(Integer, primary_key=True, index=True)
16
+ title = Column(String, index=True)
17
+ url = Column(String) # YouTube Embed ID or URL
18
+ description = Column(String)
19
+
20
+ class Comment(Base):
21
+ __tablename__ = "comments"
22
+ id = Column(Integer, primary_key=True, index=True)
23
+ video_id = Column(Integer, ForeignKey("videos.id"))
24
+ user = Column(String)
25
+ text = Column(Text)
26
+ timestamp = Column(String) # ISO format
27
+
28
+ # Analysis fields
29
+ is_toxic = Column(Boolean, default=False)
30
+ toxicity_score = Column(Float, default=0.0)
31
+ flagged_reason = Column(String, nullable=True)
32
+
33
+ def init_db():
34
+ Base.metadata.create_all(bind=engine)
schemas.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel
2
+ from typing import Optional, List
3
+
4
+ # Video Schemas
5
+ class VideoBase(BaseModel):
6
+ title: str
7
+ url: str
8
+ description: Optional[str] = None
9
+
10
+ class VideoCreate(VideoBase):
11
+ pass
12
+
13
+ class Video(VideoBase):
14
+ id: int
15
+ class Config:
16
+ orm_mode = True
17
+
18
+ # Comment Schemas
19
+ class CommentBase(BaseModel):
20
+ video_id: int
21
+ user: str
22
+ text: str
23
+ timestamp: Optional[str] = None
24
+
25
+ class CommentCreate(CommentBase):
26
+ pass
27
+
28
+ class Comment(CommentBase):
29
+ id: int
30
+ is_toxic: bool
31
+ toxicity_score: float
32
+ flagged_reason: Optional[str] = None
33
+
34
+ class Config:
35
+ orm_mode = True