sahadev10 commited on
Commit
101cf83
·
verified ·
1 Parent(s): 6df005a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -1
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
@@ -73,8 +76,10 @@ import requests
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
 
@@ -128,6 +133,39 @@ def send_to_backend(image_buffer, user_id):
128
  return f"❌ Upload failed: {response.status_code} - {response.text}"
129
 
130
  except Exception as e:
131
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
 
133
 
 
62
 
63
 
64
  # iface.launch()
65
+
66
+
67
+
68
  import gradio as gr
69
  import torch
70
  import numpy as np
 
76
  import io
77
  import warnings
78
 
79
+ # Suppress deprecated torch warnings
80
  warnings.filterwarnings("ignore")
81
 
82
+ # --- Load the pre-trained StyleGAN model ---
83
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
84
  model_path = 'dress_model.pkl'
85
 
 
133
  return f"❌ Upload failed: {response.status_code} - {response.text}"
134
 
135
  except Exception as e:
136
+ return f"⚠️ Error: {str(e)}"
137
+
138
+ # --- Gradio UI ---
139
+ with gr.Blocks(title="Style Mixing for Clothing Design") as iface:
140
+
141
+ user_id_state = gr.State()
142
+
143
+ @iface.load
144
+ def on_load(request: gr.Request):
145
+ user_id = request.query_params.get('user_id', '')
146
+ return user_id
147
+
148
+ gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")
149
+
150
+ with gr.Row():
151
+ image1_input = gr.Image(label="First Clothing Image", type="filepath")
152
+ image2_input = gr.Image(label="Second Clothing Image", type="filepath")
153
+
154
+ mix_slider = gr.Slider(label="Style Mixing Strength (Layers 0 to N)", minimum=0, maximum=9, step=1, value=5)
155
+
156
+ with gr.Row():
157
+ output_image = gr.Image(label="Mixed Clothing Design")
158
+ save_button = gr.Button("Download & Save to Database")
159
+
160
+ image_buffer = gr.State()
161
+ save_status = gr.Textbox(label="Save Status", interactive=False)
162
+
163
+ def mix_and_store(image1, image2, mix_value):
164
+ result_image, buffer = style_mixing_interface(image1, image2, mix_value)
165
+ return result_image, buffer
166
+
167
+ mix_slider.change(mix_and_store, inputs=[image1_input, image2_input, mix_slider], outputs=[output_image, image_buffer])
168
+ save_button.click(send_to_backend, inputs=[image_buffer, user_id_state], outputs=[save_status])
169
 
170
+ iface.launch()
171