Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -408,12 +408,33 @@ async def process_story(story: StoryCreationDTO, background_tasks: BackgroundTas
|
|
| 408 |
async def get_results(task_id: str):
|
| 409 |
if task_id not in tasks:
|
| 410 |
return {"status": "not_found"}
|
|
|
|
| 411 |
task = tasks[task_id]
|
|
|
|
| 412 |
if task["status"] == "processing":
|
| 413 |
return {"status": "processing"}
|
|
|
|
| 414 |
if task["status"] == "failed":
|
| 415 |
-
return {
|
| 416 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 417 |
|
| 418 |
@app.get("/")
|
| 419 |
def root():
|
|
|
|
| 408 |
async def get_results(task_id: str):
|
| 409 |
if task_id not in tasks:
|
| 410 |
return {"status": "not_found"}
|
| 411 |
+
|
| 412 |
task = tasks[task_id]
|
| 413 |
+
|
| 414 |
if task["status"] == "processing":
|
| 415 |
return {"status": "processing"}
|
| 416 |
+
|
| 417 |
if task["status"] == "failed":
|
| 418 |
+
return {
|
| 419 |
+
"status": "failed",
|
| 420 |
+
"error": task.get("error", "Unknown error")
|
| 421 |
+
}
|
| 422 |
+
|
| 423 |
+
# Ensure result exists and has all required fields
|
| 424 |
+
result = task.get("result")
|
| 425 |
+
if result and all(k in result for k in ("fileName", "duration", "audioPath")):
|
| 426 |
+
#clearing cache
|
| 427 |
+
print(f"all fields are available {result}")
|
| 428 |
+
for file_path in download_cache.values():
|
| 429 |
+
if os.path.exists(file_path):
|
| 430 |
+
os.remove(file_path)
|
| 431 |
+
download_cache.clear()
|
| 432 |
+
|
| 433 |
+
return {"status": "completed", **result}
|
| 434 |
+
else:
|
| 435 |
+
print(f"missing field {result}")
|
| 436 |
+
# If result is missing fields, mark as still processing
|
| 437 |
+
return {"status": "processing"}
|
| 438 |
|
| 439 |
@app.get("/")
|
| 440 |
def root():
|