Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,14 +23,15 @@ app = FastAPI()
|
|
| 23 |
# FRONTEND_URL = https://your-app.vercel.app
|
| 24 |
# For local dev it defaults to localhost:5173
|
| 25 |
|
| 26 |
-
|
| 27 |
-
FRONTEND_URL = "https://image-stylizer-deploy.vercel.app"
|
| 28 |
|
| 29 |
app.add_middleware(
|
| 30 |
CORSMiddleware,
|
| 31 |
allow_origins=[
|
| 32 |
-
|
| 33 |
-
"
|
|
|
|
| 34 |
],
|
| 35 |
allow_credentials=True,
|
| 36 |
allow_methods=["*"],
|
|
@@ -109,7 +110,7 @@ def save_image_tensor(tensor, path: Path):
|
|
| 109 |
img = tensor.detach().float().cpu()[0].clamp(0, 1).permute(1, 2, 0).numpy() * 255
|
| 110 |
Image.fromarray(img.astype("uint8")).save(path)
|
| 111 |
|
| 112 |
-
def stylize_image(img: Image.Image, model, img_size: int =
|
| 113 |
transform = transforms.Compose([
|
| 114 |
transforms.Resize(img_size),
|
| 115 |
transforms.ToTensor()
|
|
@@ -117,7 +118,7 @@ def stylize_image(img: Image.Image, model, img_size: int = 512):
|
|
| 117 |
x = transform(img).unsqueeze(0).to(device)
|
| 118 |
with torch.no_grad():
|
| 119 |
# autocast only when GPU is available, safe no-op on CPU
|
| 120 |
-
with torch.cuda.amp.autocast(enabled=use_amp):
|
| 121 |
y = model(x)
|
| 122 |
return y
|
| 123 |
|
|
|
|
| 23 |
# FRONTEND_URL = https://your-app.vercel.app
|
| 24 |
# For local dev it defaults to localhost:5173
|
| 25 |
|
| 26 |
+
FRONTEND_URL = os.environ.get("FRONTEND_URL")
|
| 27 |
+
# FRONTEND_URL = "https://image-stylizer-deploy.vercel.app"
|
| 28 |
|
| 29 |
app.add_middleware(
|
| 30 |
CORSMiddleware,
|
| 31 |
allow_origins=[
|
| 32 |
+
FRONTEND_URL
|
| 33 |
+
# "https://image-stylizer-deploy.vercel.app",
|
| 34 |
+
# "http://localhost:5173", # for local testing
|
| 35 |
],
|
| 36 |
allow_credentials=True,
|
| 37 |
allow_methods=["*"],
|
|
|
|
| 110 |
img = tensor.detach().float().cpu()[0].clamp(0, 1).permute(1, 2, 0).numpy() * 255
|
| 111 |
Image.fromarray(img.astype("uint8")).save(path)
|
| 112 |
|
| 113 |
+
def stylize_image(img: Image.Image, model, img_size: int = 256):
|
| 114 |
transform = transforms.Compose([
|
| 115 |
transforms.Resize(img_size),
|
| 116 |
transforms.ToTensor()
|
|
|
|
| 118 |
x = transform(img).unsqueeze(0).to(device)
|
| 119 |
with torch.no_grad():
|
| 120 |
# autocast only when GPU is available, safe no-op on CPU
|
| 121 |
+
# with torch.cuda.amp.autocast(enabled=use_amp):
|
| 122 |
y = model(x)
|
| 123 |
return y
|
| 124 |
|