sahadev10 commited on
Commit
6df005a
·
verified ·
1 Parent(s): 8efbff9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -52
app.py CHANGED
@@ -73,10 +73,8 @@ import requests
73
  import io
74
  import warnings
75
 
76
- # Suppress deprecated torch warnings
77
  warnings.filterwarnings("ignore")
78
 
79
- # --- Load the pre-trained StyleGAN model ---
80
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
81
  model_path = 'dress_model.pkl'
82
 
@@ -116,7 +114,7 @@ def style_mixing_interface(image1, image2, mix_value):
116
 
117
  def send_to_backend(image_buffer, user_id):
118
  if not user_id:
119
- return "❌ user_id not found in URL."
120
 
121
  try:
122
  files = {'file': ('generated_image.png', image_buffer, 'image/png')}
@@ -130,54 +128,6 @@ def send_to_backend(image_buffer, user_id):
130
  return f"❌ Upload failed: {response.status_code} - {response.text}"
131
 
132
  except Exception as e:
133
- return f"⚠️ Error: {str(e)}"
134
-
135
- # --- Gradio UI ---
136
- with gr.Blocks(title="Style Mixing for Clothing Design") as iface:
137
-
138
- user_id_state = gr.State()
139
-
140
- gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")
141
-
142
- with gr.Row():
143
- image1_input = gr.Image(label="First Clothing Image", type="filepath")
144
- image2_input = gr.Image(label="Second Clothing Image", type="filepath")
145
-
146
- mix_slider = gr.Slider(label="Style Mixing Strength (Layers 0 to N)", minimum=0, maximum=9, step=1, value=5)
147
-
148
- with gr.Row():
149
- output_image = gr.Image(label="Mixed Clothing Design")
150
- save_button = gr.Button("Download & Save to Database")
151
-
152
- image_buffer = gr.State()
153
- save_status = gr.Textbox(label="Save Status", interactive=False)
154
-
155
- def mix_and_store(image1, image2, mix_value):
156
- result_image, buffer = style_mixing_interface(image1, image2, mix_value)
157
- return result_image, buffer
158
-
159
- mix_slider.change(
160
- mix_and_store,
161
- inputs=[image1_input, image2_input, mix_slider],
162
- outputs=[output_image, image_buffer]
163
- )
164
-
165
- save_button.click(
166
- send_to_backend,
167
- inputs=[image_buffer, user_id_state],
168
- outputs=[save_status]
169
- )
170
-
171
- @iface.load
172
- def on_load(request: gr.Request):
173
- user_id = request.query_params.get("user_id", "")
174
- return gr.update(value=user_id) # This updates the user_id_state
175
-
176
- # Bind the return of on_load to user_id_state
177
- iface.load(on_load, None, [user_id_state])
178
-
179
- iface.launch()
180
-
181
-
182
 
183
 
 
73
  import io
74
  import warnings
75
 
 
76
  warnings.filterwarnings("ignore")
77
 
 
78
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
79
  model_path = 'dress_model.pkl'
80
 
 
114
 
115
  def send_to_backend(image_buffer, user_id):
116
  if not user_id:
117
+ return "❌ user_id not found."
118
 
119
  try:
120
  files = {'file': ('generated_image.png', image_buffer, 'image/png')}
 
128
  return f"❌ Upload failed: {response.status_code} - {response.text}"
129
 
130
  except Exception as e:
131
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133