File size: 673 Bytes
e4fc05f
e523315
 
 
 
 
e4fc05f
 
e523315
 
 
 
 
 
87e5f62
e4fc05f
e523315
 
e4fc05f
e523315
 
e4fc05f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# app.py
from fastapi import FastAPI, Request
from transformers import pipeline

app = FastAPI()

# Modelo leve e gratuito que funciona em português
generator = pipeline("text-generation", model="pierreguillou/tiny-random-gpt2-portuguese", max_length=200)

@app.post("/gerar")
async def gerar_historia(req: Request):
    body = await req.json()
    relato = body.get("relato", "")
    estilo = body.get("estilo", "")

    prompt = f"Escreva uma história no estilo {estilo} baseada neste relato: {relato}"

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