Spaces:
Paused
Paused
Muhammad Usman Nazir commited on
Commit ·
66f795f
1
Parent(s): f7df04f
fix: add GZipMiddleware for response compression and reduce MAX_DIM for image resizing
Browse files
app.py
CHANGED
|
@@ -26,6 +26,7 @@ import numpy as np
|
|
| 26 |
import torch
|
| 27 |
from fastapi import FastAPI, File, HTTPException, Response, UploadFile, BackgroundTasks
|
| 28 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 29 |
from fastapi.responses import StreamingResponse
|
| 30 |
from fastapi.staticfiles import StaticFiles
|
| 31 |
from PIL import Image
|
|
@@ -218,6 +219,7 @@ def _load_intrinsic_model():
|
|
| 218 |
|
| 219 |
|
| 220 |
app = FastAPI()
|
|
|
|
| 221 |
app.add_middleware(
|
| 222 |
CORSMiddleware,
|
| 223 |
allow_origins=["https://room-editor-9y3b.vercel.app"],
|
|
@@ -943,7 +945,7 @@ def build_segmentation_bundle(contents: bytes):
|
|
| 943 |
|
| 944 |
t0 = time.perf_counter()
|
| 945 |
img = Image.open(io.BytesIO(contents)).convert("RGB")
|
| 946 |
-
MAX_DIM =
|
| 947 |
if max(img.width, img.height) > MAX_DIM:
|
| 948 |
scale = MAX_DIM / max(img.width, img.height)
|
| 949 |
img = img.resize((int(img.width * scale), int(img.height * scale)), Image.LANCZOS)
|
|
|
|
| 26 |
import torch
|
| 27 |
from fastapi import FastAPI, File, HTTPException, Response, UploadFile, BackgroundTasks
|
| 28 |
from fastapi.middleware.cors import CORSMiddleware
|
| 29 |
+
from fastapi.middleware.gzip import GZipMiddleware
|
| 30 |
from fastapi.responses import StreamingResponse
|
| 31 |
from fastapi.staticfiles import StaticFiles
|
| 32 |
from PIL import Image
|
|
|
|
| 219 |
|
| 220 |
|
| 221 |
app = FastAPI()
|
| 222 |
+
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
| 223 |
app.add_middleware(
|
| 224 |
CORSMiddleware,
|
| 225 |
allow_origins=["https://room-editor-9y3b.vercel.app"],
|
|
|
|
| 945 |
|
| 946 |
t0 = time.perf_counter()
|
| 947 |
img = Image.open(io.BytesIO(contents)).convert("RGB")
|
| 948 |
+
MAX_DIM = 640
|
| 949 |
if max(img.width, img.height) > MAX_DIM:
|
| 950 |
scale = MAX_DIM / max(img.width, img.height)
|
| 951 |
img = img.resize((int(img.width * scale), int(img.height * scale)), Image.LANCZOS)
|