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
|
|
@@ -84,9 +83,6 @@ 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 dictionary to store user_id based on IP
|
| 88 |
-
user_ids = {}
|
| 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]
|
|
@@ -118,14 +114,13 @@ def style_mixing_interface(image1, image2, mix_value):
|
|
| 118 |
buffer.seek(0)
|
| 119 |
return mixed_img, buffer
|
| 120 |
|
| 121 |
-
def send_to_backend(image_buffer,
|
| 122 |
-
user_id = user_ids.get(request.client.host)
|
| 123 |
if not user_id:
|
| 124 |
return "❌ user_id not found in URL."
|
| 125 |
|
| 126 |
try:
|
| 127 |
files = {'file': ('generated_image.png', image_buffer, 'image/png')}
|
| 128 |
-
url = f"https://361d-103-40-74-78.ngrok-free.app/customisation/upload/
|
| 129 |
|
| 130 |
response = requests.post(url, files=files)
|
| 131 |
|
|
@@ -139,13 +134,13 @@ def send_to_backend(image_buffer, request: gr.Request):
|
|
| 139 |
|
| 140 |
# --- Gradio UI ---
|
| 141 |
with gr.Blocks(title="Style Mixing for Clothing Design") as iface:
|
|
|
|
|
|
|
| 142 |
|
| 143 |
@iface.load
|
| 144 |
def on_load(request: gr.Request):
|
| 145 |
-
user_id = request.query_params.get('user_id')
|
| 146 |
-
|
| 147 |
-
user_ids[request.client.host] = user_id
|
| 148 |
-
return
|
| 149 |
|
| 150 |
gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")
|
| 151 |
|
|
@@ -167,9 +162,10 @@ with gr.Blocks(title="Style Mixing for Clothing Design") as iface:
|
|
| 167 |
return result_image, buffer
|
| 168 |
|
| 169 |
mix_slider.change(mix_and_store, inputs=[image1_input, image2_input, mix_slider], outputs=[output_image, image_buffer])
|
| 170 |
-
save_button.click(send_to_backend, inputs=[image_buffer], outputs=[save_status])
|
| 171 |
|
| 172 |
iface.launch()
|
| 173 |
|
| 174 |
|
| 175 |
|
|
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
# iface.launch()
|
|
|
|
| 65 |
import gradio as gr
|
| 66 |
import torch
|
| 67 |
import numpy as np
|
|
|
|
| 83 |
with open(model_path, 'rb') as f:
|
| 84 |
G = legacy.load_network_pkl(f)['G_ema'].to(device)
|
| 85 |
|
|
|
|
|
|
|
|
|
|
| 86 |
def mix_styles(image1_path, image2_path, styles_to_mix):
|
| 87 |
image1_name = os.path.splitext(os.path.basename(image1_path))[0]
|
| 88 |
image2_name = os.path.splitext(os.path.basename(image2_path))[0]
|
|
|
|
| 114 |
buffer.seek(0)
|
| 115 |
return mixed_img, buffer
|
| 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')}
|
| 123 |
+
url = f"https://361d-103-40-74-78.ngrok-free.app/customisation/upload/{user_id}"
|
| 124 |
|
| 125 |
response = requests.post(url, files=files)
|
| 126 |
|
|
|
|
| 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 |
@iface.load
|
| 141 |
def on_load(request: gr.Request):
|
| 142 |
+
user_id = request.query_params.get('user_id', '')
|
| 143 |
+
return user_id
|
|
|
|
|
|
|
| 144 |
|
| 145 |
gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")
|
| 146 |
|
|
|
|
| 162 |
return result_image, buffer
|
| 163 |
|
| 164 |
mix_slider.change(mix_and_store, inputs=[image1_input, image2_input, mix_slider], outputs=[output_image, image_buffer])
|
| 165 |
+
save_button.click(send_to_backend, inputs=[image_buffer, user_id_state], outputs=[save_status])
|
| 166 |
|
| 167 |
iface.launch()
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
+
|