Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- Dockerfile +16 -0
- app.py +40 -0
- crud.py +73 -0
- database.py +53 -0
- models.py +30 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.9
|
| 5 |
+
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
+
from .database import init_db
|
| 4 |
+
from .models import UserCreate, UserLogin, SessionCreate, ABADetails
|
| 5 |
+
from .crud import create_user, get_user_by_email, create_session, create_aba_entry
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
init_db()
|
| 9 |
+
|
| 10 |
+
app.add_middleware(
|
| 11 |
+
CORSMiddleware,
|
| 12 |
+
allow_origins=["*"],
|
| 13 |
+
allow_credentials=True,
|
| 14 |
+
allow_methods=["*"],
|
| 15 |
+
allow_headers=["*"],
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
@app.post("/register")
|
| 19 |
+
def register(user: UserCreate):
|
| 20 |
+
if get_user_by_email(user.email):
|
| 21 |
+
raise HTTPException(status_code=400, detail="Email já registrado.")
|
| 22 |
+
create_user(user.name, user.email, user.password, user.role)
|
| 23 |
+
return {"message": "Usuário registrado com sucesso!"}
|
| 24 |
+
|
| 25 |
+
@app.post("/login")
|
| 26 |
+
def login(user: UserLogin):
|
| 27 |
+
db_user = get_user_by_email(user.email)
|
| 28 |
+
if db_user and db_user[3] == user.password:
|
| 29 |
+
return {"message": "Login bem-sucedido!", "user_id": db_user[0], "role": db_user[4]}
|
| 30 |
+
raise HTTPException(status_code=401, detail="Credenciais inválidas.")
|
| 31 |
+
|
| 32 |
+
@app.post("/sessions")
|
| 33 |
+
def add_session(session: SessionCreate):
|
| 34 |
+
create_session(session)
|
| 35 |
+
return {"message": "Sessão registrada!"}
|
| 36 |
+
|
| 37 |
+
@app.post("/aba")
|
| 38 |
+
def add_aba_data(data: ABADetails):
|
| 39 |
+
create_aba_entry(data)
|
| 40 |
+
return {"message": "Dados ABA registrados!"}
|
crud.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
from typing import Optional
|
| 3 |
+
|
| 4 |
+
class UserCreate(BaseModel):
|
| 5 |
+
name: str
|
| 6 |
+
email: str
|
| 7 |
+
password: str
|
| 8 |
+
role: str
|
| 9 |
+
|
| 10 |
+
class UserLogin(BaseModel):
|
| 11 |
+
email: str
|
| 12 |
+
password: str
|
| 13 |
+
|
| 14 |
+
class SessionCreate(BaseModel):
|
| 15 |
+
user_id: int
|
| 16 |
+
date: str
|
| 17 |
+
activities: Optional[str] = None
|
| 18 |
+
progress: Optional[str] = None
|
| 19 |
+
challenges: Optional[str] = None
|
| 20 |
+
observations: Optional[str] = None
|
| 21 |
+
performance_score: Optional[int] = None
|
| 22 |
+
task_completion: Optional[int] = None
|
| 23 |
+
behavior_rating: Optional[int] = None
|
| 24 |
+
|
| 25 |
+
class ABADetails(BaseModel):
|
| 26 |
+
session_id: int
|
| 27 |
+
behavior: str
|
| 28 |
+
frequency: int
|
| 29 |
+
reinforcer: str
|
| 30 |
+
technique: str
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
### backend/crud.py
|
| 34 |
+
import sqlite3
|
| 35 |
+
from .database import get_connection
|
| 36 |
+
|
| 37 |
+
def create_user(name, email, password, role):
|
| 38 |
+
conn = get_connection()
|
| 39 |
+
cur = conn.cursor()
|
| 40 |
+
cur.execute("INSERT INTO users (name, email, password, role) VALUES (?, ?, ?, ?)",
|
| 41 |
+
(name, email, password, role))
|
| 42 |
+
conn.commit()
|
| 43 |
+
conn.close()
|
| 44 |
+
|
| 45 |
+
def get_user_by_email(email):
|
| 46 |
+
conn = get_connection()
|
| 47 |
+
cur = conn.cursor()
|
| 48 |
+
cur.execute("SELECT * FROM users WHERE email = ?", (email,))
|
| 49 |
+
user = cur.fetchone()
|
| 50 |
+
conn.close()
|
| 51 |
+
return user
|
| 52 |
+
|
| 53 |
+
def create_session(data):
|
| 54 |
+
conn = get_connection()
|
| 55 |
+
cur = conn.cursor()
|
| 56 |
+
cur.execute("""
|
| 57 |
+
INSERT INTO sessions (user_id, date, activities, progress, challenges, observations,
|
| 58 |
+
performance_score, task_completion, behavior_rating)
|
| 59 |
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
| 60 |
+
""", (data.user_id, data.date, data.activities, data.progress, data.challenges, data.observations,
|
| 61 |
+
data.performance_score, data.task_completion, data.behavior_rating))
|
| 62 |
+
conn.commit()
|
| 63 |
+
conn.close()
|
| 64 |
+
|
| 65 |
+
def create_aba_entry(data):
|
| 66 |
+
conn = get_connection()
|
| 67 |
+
cur = conn.cursor()
|
| 68 |
+
cur.execute("""
|
| 69 |
+
INSERT INTO aba_data (session_id, behavior, frequency, reinforcer, technique)
|
| 70 |
+
VALUES (?, ?, ?, ?, ?)
|
| 71 |
+
""", (data.session_id, data.behavior, data.frequency, data.reinforcer, data.technique))
|
| 72 |
+
conn.commit()
|
| 73 |
+
conn.close()
|
database.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
DB_PATH = Path("db/aba_data.db")
|
| 5 |
+
DB_PATH.parent.mkdir(exist_ok=True)
|
| 6 |
+
|
| 7 |
+
def init_db():
|
| 8 |
+
with sqlite3.connect(DB_PATH) as conn:
|
| 9 |
+
cursor = conn.cursor()
|
| 10 |
+
|
| 11 |
+
cursor.execute("""
|
| 12 |
+
CREATE TABLE IF NOT EXISTS users (
|
| 13 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 14 |
+
name TEXT NOT NULL,
|
| 15 |
+
email TEXT UNIQUE NOT NULL,
|
| 16 |
+
password TEXT NOT NULL,
|
| 17 |
+
role TEXT NOT NULL
|
| 18 |
+
)
|
| 19 |
+
""")
|
| 20 |
+
|
| 21 |
+
cursor.execute("""
|
| 22 |
+
CREATE TABLE IF NOT EXISTS sessions (
|
| 23 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 24 |
+
user_id INTEGER NOT NULL,
|
| 25 |
+
date TEXT NOT NULL,
|
| 26 |
+
activities TEXT,
|
| 27 |
+
progress TEXT,
|
| 28 |
+
challenges TEXT,
|
| 29 |
+
observations TEXT,
|
| 30 |
+
performance_score INTEGER,
|
| 31 |
+
task_completion INTEGER,
|
| 32 |
+
behavior_rating INTEGER,
|
| 33 |
+
FOREIGN KEY(user_id) REFERENCES users(id)
|
| 34 |
+
)
|
| 35 |
+
""")
|
| 36 |
+
|
| 37 |
+
cursor.execute("""
|
| 38 |
+
CREATE TABLE IF NOT EXISTS aba_data (
|
| 39 |
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 40 |
+
session_id INTEGER NOT NULL,
|
| 41 |
+
behavior TEXT,
|
| 42 |
+
frequency INTEGER,
|
| 43 |
+
reinforcer TEXT,
|
| 44 |
+
technique TEXT,
|
| 45 |
+
FOREIGN KEY(session_id) REFERENCES sessions(id)
|
| 46 |
+
)
|
| 47 |
+
""")
|
| 48 |
+
|
| 49 |
+
conn.commit()
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def get_connection():
|
| 53 |
+
return sqlite3.connect(DB_PATH)
|
models.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel
|
| 2 |
+
from typing import Optional
|
| 3 |
+
|
| 4 |
+
class UserCreate(BaseModel):
|
| 5 |
+
name: str
|
| 6 |
+
email: str
|
| 7 |
+
password: str
|
| 8 |
+
role: str
|
| 9 |
+
|
| 10 |
+
class UserLogin(BaseModel):
|
| 11 |
+
email: str
|
| 12 |
+
password: str
|
| 13 |
+
|
| 14 |
+
class SessionCreate(BaseModel):
|
| 15 |
+
user_id: int
|
| 16 |
+
date: str
|
| 17 |
+
activities: Optional[str] = None
|
| 18 |
+
progress: Optional[str] = None
|
| 19 |
+
challenges: Optional[str] = None
|
| 20 |
+
observations: Optional[str] = None
|
| 21 |
+
performance_score: Optional[int] = None
|
| 22 |
+
task_completion: Optional[int] = None
|
| 23 |
+
behavior_rating: Optional[int] = None
|
| 24 |
+
|
| 25 |
+
class ABADetails(BaseModel):
|
| 26 |
+
session_id: int
|
| 27 |
+
behavior: str
|
| 28 |
+
frequency: int
|
| 29 |
+
reinforcer: str
|
| 30 |
+
technique: str
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
sqlalchemy
|
| 4 |
+
pydantic
|
| 5 |
+
requests
|
| 6 |
+
streamlit
|
| 7 |
+
matplotlib
|