Spaces:
Runtime error
Runtime error
File size: 2,657 Bytes
46085c7 5f2a085 46085c7 | 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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | from __future__ import annotations
from datetime import datetime
from uuid import uuid4
from sqlalchemy import DateTime, Float, String, Text, func
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
def new_id() -> str:
return str(uuid4())
class Base(DeclarativeBase):
pass
class Incident(Base):
__tablename__ = "incidents"
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=new_id)
user_id: Mapped[str] = mapped_column(String(255), index=True)
target_user_id: Mapped[str] = mapped_column(String(255), index=True)
timestamp: Mapped[datetime] = mapped_column(DateTime(timezone=True), index=True)
text: Mapped[str] = mapped_column(Text)
status: Mapped[str] = mapped_column(String(32), default="queued", index=True)
severity_level: Mapped[str] = mapped_column(String(32), index=True)
severity_score: Mapped[float] = mapped_column(Float, index=True)
aggression_score: Mapped[float] = mapped_column(Float)
intent_score: Mapped[float] = mapped_column(Float)
repetition_score: Mapped[float] = mapped_column(Float)
toxic_score: Mapped[float] = mapped_column(Float)
insult_score: Mapped[float] = mapped_column(Float)
identity_attack_score: Mapped[float] = mapped_column(Float)
model_name: Mapped[str] = mapped_column(String(128))
model_version: Mapped[str] = mapped_column(String(128))
raw_model_output: Mapped[dict] = mapped_column(JSONB)
review_note: Mapped[str | None] = mapped_column(Text, nullable=True)
reviewed_by_user_id: Mapped[str | None] = mapped_column(String(255), nullable=True)
reviewed_by_email: Mapped[str | None] = mapped_column(String(255), nullable=True)
moderated_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True, index=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True),
server_default=func.now(),
onupdate=func.now(),
)
class Alert(Base):
__tablename__ = "alerts"
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=new_id)
incident_id: Mapped[str] = mapped_column(String(36), index=True)
severity_score: Mapped[float] = mapped_column(Float)
recipient: Mapped[str] = mapped_column(String(255))
payload: Mapped[dict] = mapped_column(JSONB)
delivery_state: Mapped[str] = mapped_column(String(32), default="stubbed")
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|