sahadev10 commited on
Commit
9be4b34
·
verified ·
1 Parent(s): 4c5b602

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -17
app.py CHANGED
@@ -62,6 +62,9 @@
62
 
63
 
64
  # iface.launch()
 
 
 
65
  import gradio as gr
66
  import torch
67
  import numpy as np
@@ -71,7 +74,6 @@ import legacy
71
  import torch_utils
72
  import requests
73
  import io
74
- import jwt # PyJWT
75
  import warnings
76
 
77
  # Suppress deprecated torch warnings
@@ -84,8 +86,8 @@ model_path = 'dress_model.pkl'
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]
@@ -119,17 +121,11 @@ def style_mixing_interface(image1, image2, mix_value):
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:
130
- return "❌ user_id not found in JWT."
131
-
132
- # Prepare image upload
133
  files = {'file': ('generated_image.png', image_buffer, 'image/png')}
134
  url = f"http://localhost:3000/customisation/upload/{user_id}"
135
 
@@ -140,8 +136,6 @@ def send_to_backend(image_buffer, request: gr.Request):
140
  else:
141
  return f"❌ Upload failed: {response.status_code} - {response.text}"
142
 
143
- except jwt.DecodeError:
144
- return "❌ Invalid JWT token."
145
  except Exception as e:
146
  return f"⚠️ Error: {str(e)}"
147
 
@@ -150,9 +144,9 @@ 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.")
 
62
 
63
 
64
  # iface.launch()
65
+
66
+
67
+
68
  import gradio as gr
69
  import torch
70
  import numpy as np
 
74
  import torch_utils
75
  import requests
76
  import io
 
77
  import warnings
78
 
79
  # Suppress deprecated torch warnings
 
86
  with open(model_path, 'rb') as f:
87
  G = legacy.load_network_pkl(f)['G_ema'].to(device)
88
 
89
+ # Global variable to store user_id (per IP/session) not ideal for production
90
+ user_ids = {}
91
 
92
  def mix_styles(image1_path, image2_path, styles_to_mix):
93
  image1_name = os.path.splitext(os.path.basename(image1_path))[0]
 
121
  return mixed_img, buffer
122
 
123
  def send_to_backend(image_buffer, request: gr.Request):
124
+ user_id = user_ids.get(request.client.host)
125
+ if not user_id:
126
+ return "❌ user_id not found in URL."
127
 
128
  try:
 
 
 
 
 
 
129
  files = {'file': ('generated_image.png', image_buffer, 'image/png')}
130
  url = f"http://localhost:3000/customisation/upload/{user_id}"
131
 
 
136
  else:
137
  return f"❌ Upload failed: {response.status_code} - {response.text}"
138
 
 
 
139
  except Exception as e:
140
  return f"⚠️ Error: {str(e)}"
141
 
 
144
 
145
  @iface.load
146
  def on_load(request: gr.Request):
147
+ user_id = request.query_params.get('user_id')
148
+ if user_id:
149
+ user_ids[request.client.host] = user_id
150
  return
151
 
152
  gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")