just-api / app.py
Voffchik's picture
Update app.py
174e599 verified
raw
history blame contribute delete
693 Bytes
from fastapi import FastAPI
from pydantic import BaseModel # для автоматического разбора
from transformers import pipeline
import os
import asyncio
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
global needModel
needModel = pipeline("sentiment-analysis")
yield
app = FastAPI(lifespan=lifespan)
class Request(BaseModel):
text: str
number: int
@app.post("/message")
async def model(request: Request):
try:
# Возвращаем текст в верхнем регистре
return {"result": request.text.upper()}
except Exception as e:
return {"error": str(e)}