Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,21 @@
|
|
1 |
from fastapi import FastAPI, Request
|
2 |
from transformers import pipeline
|
3 |
-
import uvicorn
|
4 |
|
5 |
app = FastAPI()
|
6 |
|
7 |
-
|
|
|
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][
|
18 |
return {"historia": resultado}
|
19 |
except Exception as e:
|
20 |
return {"erro": str(e)}
|
|
|
1 |
from fastapi import FastAPI, Request
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
# Corrigido para usar o modelo compat铆vel com text-generation
|
7 |
+
generator = pipeline("text-generation", model="pierreguillou/pt-small", 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 |
+
|
15 |
prompt = f"Crie uma hist贸ria no estilo {estilo}. Baseie-se neste relato: {relato}"
|
16 |
|
17 |
try:
|
18 |
+
resultado = generator(prompt, max_new_tokens=200)[0]["generated_text"]
|
19 |
return {"historia": resultado}
|
20 |
except Exception as e:
|
21 |
return {"erro": str(e)}
|