Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
|
6 |
+
generator = pipeline("text-generation", model="pierreguillou/pt-small", max_length=300)
|
7 |
+
|
8 |
+
@app.post("/gerar")
|
9 |
+
async def gerar_historia(req: Request):
|
10 |
+
body = await req.json()
|
11 |
+
relato = body.get("relato", "")
|
12 |
+
estilo = body.get("estilo", "")
|
13 |
+
prompt = f"Crie uma hist贸ria no estilo {estilo}. Baseie-se neste relato: {relato}"
|
14 |
+
|
15 |
+
try:
|
16 |
+
resultado = generator(prompt, max_new_tokens=200)[0]["generated_text"]
|
17 |
+
return {"historia": resultado}
|
18 |
+
except Exception as e:
|
19 |
+
return {"erro": str(e)}
|