File size: 693 Bytes
93e4e76 174e599 220c6b7 02c6aa4 220c6b7 116a867 65a690d 220c6b7 02c6aa4 220c6b7 174e599 220c6b7 174e599 220c6b7 116a867 174e599 220c6b7 2b704d8 220c6b7 2b704d8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
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)}
|