/
himozaa
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
himozaa
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
main.py
37 строк
709 B
Shankly8642
style(ci): add flake8 configuration and fix lint issues
12 май 2026, 16:09
12 май 2026, 16:09
5d32ea7
Код
Авторство
О чём код?
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))