/
vladimir.suter
/
SE_FastAPI_Example
Обзор
Документация
Войти
/
vladimir.suter
/
SE_FastAPI_Example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
main.py
41 строка
1008 B
Vladimir
Add CI/CD pipeline, flake8 config and requirements
11 июн 2026, 07:44
11 июн 2026, 07:44
1f58ca9
Код
Авторство
О чём код?
from fastapi import FastAPI, HTTPException from pydantic import BaseModel from ml_model import SentimentAnalyzer app = FastAPI( title="Sentiment Analysis API", version="1.0.0" ) class Item(BaseModel): text: str # Инициализация модели analyzer = SentimentAnalyzer() @app.get("/") def root(): return {"status": "ok", "service": "Sentiment Analysis API"} @app.post("/predict/") def predict(item: Item): try: if not item.text or not item.text.strip(): raise HTTPException(status_code=400, detail="Text cannot be empty") result = analyzer.predict(item.text) return { "text": item.text, "label": result['label'], "score": round(result['score'], 4) } except HTTPException: raise except Exception as e: raise HTTPException(status_code=500, detail=str(e)) if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)