Spaces:
Sleeping
Sleeping
Muhammad Usman Nazir commited on
Commit ·
d74d651
1
Parent(s): 4e3194a
fix: replace GZipMiddleware with StreamingResponse for efficient file streaming
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ import numpy as np
|
|
| 25 |
import torch
|
| 26 |
from fastapi import FastAPI, File, HTTPException, Response, UploadFile, BackgroundTasks
|
| 27 |
from fastapi.middleware.cors import CORSMiddleware
|
| 28 |
-
from fastapi.
|
| 29 |
from fastapi.staticfiles import StaticFiles
|
| 30 |
from PIL import Image
|
| 31 |
from transformers import (
|
|
@@ -217,7 +217,6 @@ def _load_intrinsic_model():
|
|
| 217 |
|
| 218 |
|
| 219 |
app = FastAPI()
|
| 220 |
-
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
| 221 |
app.add_middleware(
|
| 222 |
CORSMiddleware,
|
| 223 |
allow_origins=["https://room-editor-9y3b.vercel.app"],
|
|
@@ -1143,10 +1142,12 @@ async def viz2d_job_file(job_id: str):
|
|
| 1143 |
bundle_path = JOB_DIR / f"{job_id}.bundle.json"
|
| 1144 |
if not bundle_path.exists():
|
| 1145 |
raise HTTPException(status_code=404, detail="Job output not found.")
|
| 1146 |
-
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
|
|
|
|
|
|
| 1150 |
|
| 1151 |
|
| 1152 |
@app.post("/segment")
|
|
|
|
| 25 |
import torch
|
| 26 |
from fastapi import FastAPI, File, HTTPException, Response, UploadFile, BackgroundTasks
|
| 27 |
from fastapi.middleware.cors import CORSMiddleware
|
| 28 |
+
from fastapi.responses import StreamingResponse
|
| 29 |
from fastapi.staticfiles import StaticFiles
|
| 30 |
from PIL import Image
|
| 31 |
from transformers import (
|
|
|
|
| 217 |
|
| 218 |
|
| 219 |
app = FastAPI()
|
|
|
|
| 220 |
app.add_middleware(
|
| 221 |
CORSMiddleware,
|
| 222 |
allow_origins=["https://room-editor-9y3b.vercel.app"],
|
|
|
|
| 1142 |
bundle_path = JOB_DIR / f"{job_id}.bundle.json"
|
| 1143 |
if not bundle_path.exists():
|
| 1144 |
raise HTTPException(status_code=404, detail="Job output not found.")
|
| 1145 |
+
def iter_file():
|
| 1146 |
+
with open(bundle_path, "rb") as f:
|
| 1147 |
+
while chunk := f.read(65536):
|
| 1148 |
+
yield chunk
|
| 1149 |
+
|
| 1150 |
+
return StreamingResponse(iter_file(), media_type="application/json")
|
| 1151 |
|
| 1152 |
|
| 1153 |
@app.post("/segment")
|