Spaces:
Sleeping
Sleeping
Muhammad Usman Nazir commited on
Commit ·
f2bced4
1
Parent(s): b18255a
fix: switch to aiofiles for asynchronous file reading in viz2d_job_file
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
import base64
|
| 3 |
import io
|
|
@@ -1146,9 +1147,9 @@ async def viz2d_job_file(job_id: str):
|
|
| 1146 |
bundle_path = JOB_DIR / f"{job_id}.bundle.json"
|
| 1147 |
if not bundle_path.exists():
|
| 1148 |
raise HTTPException(status_code=404, detail="Job output not found.")
|
| 1149 |
-
def iter_file():
|
| 1150 |
-
with open(bundle_path, "rb") as f:
|
| 1151 |
-
while chunk := f.read(65536):
|
| 1152 |
yield chunk
|
| 1153 |
|
| 1154 |
return StreamingResponse(iter_file(), media_type="application/json")
|
|
|
|
| 1 |
+
import aiofiles
|
| 2 |
import asyncio
|
| 3 |
import base64
|
| 4 |
import io
|
|
|
|
| 1147 |
bundle_path = JOB_DIR / f"{job_id}.bundle.json"
|
| 1148 |
if not bundle_path.exists():
|
| 1149 |
raise HTTPException(status_code=404, detail="Job output not found.")
|
| 1150 |
+
async def iter_file():
|
| 1151 |
+
async with aiofiles.open(bundle_path, "rb") as f:
|
| 1152 |
+
while chunk := await f.read(65536):
|
| 1153 |
yield chunk
|
| 1154 |
|
| 1155 |
return StreamingResponse(iter_file(), media_type="application/json")
|