/
himozaa
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
himozaa
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
release/1
main.py
37 строк
708 B
Shankly8642
feat(validation): add input validation for request data
02 май 2026, 11:03
02 май 2026, 11:03
779b68e
Код
Авторство
О чём код?
from fastapi import FastAPI, HTTPException from transformers import pipeline from pydantic import BaseModel, Field from config import MODEL_NAME class Item(BaseModel): text: str = Field(..., min_length=1) app = FastAPI() classifier = pipeline(MODEL_NAME) def validate_text(text: str) -> str: text = text.strip() if not text: raise HTTPException(status_code=400, detail="Text must not be empty") return text @app.get("/") def root(): return {"message": "FastAPI service started!"} @app.get("/{text}") def get_params(text: str): return classifier(validate_text(text)) @app.post("/predict/") def predict(item: Item): return classifier(validate_text(item.text))