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