File size: 625 Bytes
e523315
 
c602183
e523315
 
 
c602183
e523315
 
 
 
 
 
 
 
 
c602183
e523315
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastapi import FastAPI, Request
from transformers import pipeline
import uvicorn

app = FastAPI()

generator = pipeline("text2text-generation", model="pierreguillou/t5-base-pt-small")

@app.post("/gerar")
async def gerar_historia(req: Request):
    body = await req.json()
    relato = body.get("relato", "")
    estilo = body.get("estilo", "")
    prompt = f"Crie uma história no estilo {estilo}. Baseie-se neste relato: {relato}"

    try:
        resultado = generator(prompt, max_new_tokens=200)[0]['generated_text']
        return {"historia": resultado}
    except Exception as e:
        return {"erro": str(e)}