import os import shutil import gradio as gr from PIL import Image def process_images(cloth_image, origin_image): # Convert numpy arrays to PIL images cloth_image = Image.fromarray(cloth_image) origin_image = Image.fromarray(origin_image) print(cloth_image) print(origin_image) # Define the input directory input_dir = 'TryYours-Virtual-Try-On/static' print(input_dir) # Ensure the directory exists if not os.path.exists(input_dir): os.makedirs(input_dir) # Save the uploaded images to the input directory cloth_image.save(os.path.join(input_dir, 'cloth_web.jpg')) origin_image.save(os.path.join(input_dir, 'origin_web.jpg')) print("saved") # Run your main.py script (assuming it's in the same directory) # Note: You might need to adjust the command based on your actual script's requirements os.system("python TryYours-Virtual-Try-On/main.py ") #command = ["python", "virtual-try-on/TryYours-Virtual-Try-On/main.py"] #subprocess.run(command, check=True) print("might run") # Return the final image final_image_path = os.path.join(input_dir, 'finalimg.png') return final_image_path garment_top = gr.Image(sources='upload', type="numpy") garment_down = gr.Image(sources='upload', type="numpy") demo = gr.Interface(process_images,inputs=[ garment_top, garment_down, ], outputs=["image"]) demo.launch(share=True, debug=True)