Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
|
|
1 |
from fastapi import FastAPI, Request
|
2 |
from transformers import pipeline
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
-
#
|
7 |
-
generator = pipeline("text-generation", model="pierreguillou/
|
8 |
|
9 |
@app.post("/gerar")
|
10 |
async def gerar_historia(req: Request):
|
@@ -12,10 +13,10 @@ async def gerar_historia(req: Request):
|
|
12 |
relato = body.get("relato", "")
|
13 |
estilo = body.get("estilo", "")
|
14 |
|
15 |
-
prompt = f"
|
16 |
|
17 |
try:
|
18 |
-
resultado = generator(prompt
|
19 |
return {"historia": resultado}
|
20 |
except Exception as e:
|
21 |
-
return {"erro": str(e)}
|
|
|
1 |
+
# app.py
|
2 |
from fastapi import FastAPI, Request
|
3 |
from transformers import pipeline
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
+
# Modelo leve e gratuito que funciona em portugu锚s
|
8 |
+
generator = pipeline("text-generation", model="pierreguillou/tiny-random-gpt2-portuguese", max_length=200)
|
9 |
|
10 |
@app.post("/gerar")
|
11 |
async def gerar_historia(req: Request):
|
|
|
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]['generated_text']
|
20 |
return {"historia": resultado}
|
21 |
except Exception as e:
|
22 |
+
return {"erro": str(e)}
|