Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,8 +20,11 @@ def read_root():
|
|
| 20 |
"message": "Welcome to the FastAPI text generation API! Use the /generate endpoint with a 'text' query parameter."
|
| 21 |
}
|
| 22 |
|
| 23 |
-
@app.
|
| 24 |
-
def generate(
|
|
|
|
|
|
|
|
|
|
| 25 |
try:
|
| 26 |
output = pipe(text)
|
| 27 |
return {"output": output[0]["generated_text"]}
|
|
@@ -29,4 +32,4 @@ def generate(text: str):
|
|
| 29 |
return JSONResponse(
|
| 30 |
status_code=500,
|
| 31 |
content={"error": f"An error occurred: {str(e)}"}
|
| 32 |
-
)
|
|
|
|
| 20 |
"message": "Welcome to the FastAPI text generation API! Use the /generate endpoint with a 'text' query parameter."
|
| 21 |
}
|
| 22 |
|
| 23 |
+
@app.post("/generate")
|
| 24 |
+
def generate(payload: dict):
|
| 25 |
+
text = payload.get("text", "")
|
| 26 |
+
if not text:
|
| 27 |
+
raise HTTPException(status_code=400, detail="Text input is required.")
|
| 28 |
try:
|
| 29 |
output = pipe(text)
|
| 30 |
return {"output": output[0]["generated_text"]}
|
|
|
|
| 32 |
return JSONResponse(
|
| 33 |
status_code=500,
|
| 34 |
content={"error": f"An error occurred: {str(e)}"}
|
| 35 |
+
)
|