Spaces:
Runtime error
Runtime error
Update app.py
Browse files72 unmodified lines7374757677787980818233 unmodified lines1161171181191201211227 unmodified lines13013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218372 unmodified linesimport ioimport warnings# Suppress deprecated torch warningswarnings.filterwarnings("ignore")# --- Load the pre-trained StyleGAN model ---device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')model_path = 'dress_model.pkl'33 unmodified linesdef send_to_backend(image_buffer, user_id):if not user_id:return "❌ user_id not found in URL."try:files = {'file': ('generated_image.png', image_buffer, 'image/png')}7 unmodified linesreturn f"❌ Upload failed: {response.status_code} - {response.text}"except Exception as e:return f"⚠️ Error: {str(e)}"# --- Gradio UI ---with gr.Blocks(title="Style Mixing for Clothing Design") as iface:user_id_state = gr.State()gr.Markdown("## Style Mixing for Clothing Design\nUpload two projected clothing images and mix their styles.")with gr.Row():image1_input = gr.Image(label="First Clothing Image", type="filepath")image2_input = gr.Image(label="Second Clothing Image", type="filepath")mix_slider = gr.Slider(label="Style Mixing Strength (Layers 0 to N)", minimum=0, maximum=9, step=1, value=5)with gr.Row():output_image = gr.Image(label="Mixed Clothing Design")save_button = gr.Button("Download & Save to Database")image_buffer = gr.State()save_status = gr.Textbox(label="Save Status", interactive=False)def mix_and_store(image1, image2, mix_value):result_image, buffer = style_mixing_interface(image1, image2, mix_value)return result_image, buffermix_slider.change(mix_and_store,inputs=[image1_input, image2_input, mix_slider],outputs=[output_image, image_buffer])save_button.click(send_to_backend,inputs=[image_buffer, user_id_state],outputs=[save_status])@iface.loaddef on_load(request: gr.Request):user_id = request.query_params.get("user_id", "")return gr.update(value=user_id) # This updates the user_id_state# Bind the return of on_load to user_id_stateiface.load(on_load, None, [user_id_state])iface.launch()72 unmodified lines737475767778798033 unmodified lines1141151161171181191207 unmodified lines12812913013113213372 unmodified linesimport ioimport warningswarnings.filterwarnings("ignore")device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')model_path = 'dress_model.pkl'33 unmodified linesdef send_to_backend(image_buffer, user_id):if not user_id:return "❌ user_id not found."try:files = {'file': ('generated_image.png', image_buffer, 'image/png')}7 unmodified linesreturn f"❌ Upload failed: {response.status_code} - {response.text}"except Exception as e:
app.py+2-52