Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,7 +62,6 @@
|
|
| 62 |
|
| 63 |
|
| 64 |
# iface.launch()
|
| 65 |
-
|
| 66 |
import gradio as gr
|
| 67 |
import torch
|
| 68 |
import numpy as np
|
|
@@ -72,7 +71,6 @@ import legacy
|
|
| 72 |
import torch_utils
|
| 73 |
import requests
|
| 74 |
import io
|
| 75 |
-
from http.cookies import SimpleCookie
|
| 76 |
import jwt # PyJWT
|
| 77 |
import warnings
|
| 78 |
|
|
@@ -86,6 +84,9 @@ model_path = 'dress_model.pkl'
|
|
| 86 |
with open(model_path, 'rb') as f:
|
| 87 |
G = legacy.load_network_pkl(f)['G_ema'].to(device)
|
| 88 |
|
|
|
|
|
|
|
|
|
|
| 89 |
def mix_styles(image1_path, image2_path, styles_to_mix):
|
| 90 |
image1_name = os.path.splitext(os.path.basename(image1_path))[0]
|
| 91 |
image2_name = os.path.splitext(os.path.basename(image2_path))[0]
|
|
@@ -118,18 +119,11 @@ def style_mixing_interface(image1, image2, mix_value):
|
|
| 118 |
return mixed_img, buffer
|
| 119 |
|
| 120 |
def send_to_backend(image_buffer, request: gr.Request):
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
jwt_token_cookie = cookies.get("access_token")
|
| 126 |
-
if not jwt_token_cookie:
|
| 127 |
-
return "❌ JWT token not found in cookies."
|
| 128 |
-
|
| 129 |
-
token = jwt_token_cookie.value
|
| 130 |
|
| 131 |
try:
|
| 132 |
-
# Decode JWT (no verification assuming it's a trusted local token for this case)
|
| 133 |
payload = jwt.decode(token, options={"verify_signature": False})
|
| 134 |
user_id = payload.get("user_id")
|
| 135 |
if not user_id:
|
|
@@ -153,6 +147,14 @@ def send_to_backend(image_buffer, request: gr.Request):
|
|
| 153 |
|
| 154 |
# --- Gradio UI ---
|
| 155 |
with gr.Blocks(title="Style Mixing for Clothing Design") as iface:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")
|
| 157 |
|
| 158 |
with gr.Row():
|
|
@@ -179,3 +181,4 @@ iface.launch()
|
|
| 179 |
|
| 180 |
|
| 181 |
|
|
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
# iface.launch()
|
|
|
|
| 65 |
import gradio as gr
|
| 66 |
import torch
|
| 67 |
import numpy as np
|
|
|
|
| 71 |
import torch_utils
|
| 72 |
import requests
|
| 73 |
import io
|
|
|
|
| 74 |
import jwt # PyJWT
|
| 75 |
import warnings
|
| 76 |
|
|
|
|
| 84 |
with open(model_path, 'rb') as f:
|
| 85 |
G = legacy.load_network_pkl(f)['G_ema'].to(device)
|
| 86 |
|
| 87 |
+
# Global variable to store token (Not recommended for multi-user prod use)
|
| 88 |
+
user_token = {}
|
| 89 |
+
|
| 90 |
def mix_styles(image1_path, image2_path, styles_to_mix):
|
| 91 |
image1_name = os.path.splitext(os.path.basename(image1_path))[0]
|
| 92 |
image2_name = os.path.splitext(os.path.basename(image2_path))[0]
|
|
|
|
| 119 |
return mixed_img, buffer
|
| 120 |
|
| 121 |
def send_to_backend(image_buffer, request: gr.Request):
|
| 122 |
+
token = user_token.get(request.client.host)
|
| 123 |
+
if not token:
|
| 124 |
+
return "❌ JWT token not found in URL or session."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
try:
|
|
|
|
| 127 |
payload = jwt.decode(token, options={"verify_signature": False})
|
| 128 |
user_id = payload.get("user_id")
|
| 129 |
if not user_id:
|
|
|
|
| 147 |
|
| 148 |
# --- Gradio UI ---
|
| 149 |
with gr.Blocks(title="Style Mixing for Clothing Design") as iface:
|
| 150 |
+
|
| 151 |
+
@iface.load
|
| 152 |
+
def on_load(request: gr.Request):
|
| 153 |
+
token = request.query_params.get('token')
|
| 154 |
+
if token:
|
| 155 |
+
user_token[request.client.host] = token
|
| 156 |
+
return
|
| 157 |
+
|
| 158 |
gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")
|
| 159 |
|
| 160 |
with gr.Row():
|
|
|
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
+
|