Spaces:
Sleeping
Sleeping
Download app.py from Aaronjf97/Virtualtryon: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/spaces/Aaronjf97/Virtualtryon/resolve/main/app.py
- Command line
-
hf download hf://spaces/Aaronjf97/Virtualtryon/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Aaronjf97/Virtualtryon/resolve/main/app.py
1.06 kB
| import gradio as gr | |
| import requests | |
| import os | |
| def tryon_api(selfie_path, outfit_path): | |
| url = "https://tryon-diffusion.p.rapidapi.com/try-on-file" | |
| headers = { | |
| "X-RapidAPI-Key": os.getenv("RAPIDAPI_KEY"), | |
| "X-RapidAPI-Host": "tryon-diffusion.p.rapidapi.com" | |
| } | |
| files = { | |
| "person_image": ("selfie.jpg", open(selfie_path, "rb"), "image/jpeg"), | |
| "cloth_image": ("outfit.jpg", open(outfit_path, "rb"), "image/jpeg") | |
| } | |
| response = requests.post(url, headers=headers, files=files) | |
| try: | |
| result = response.json() | |
| return result.get("output_url", "No image returned.") | |
| except: | |
| return "Error: API failed." | |
| # 🟢 FIXED: type='filepath' instead of 'file' | |
| iface = gr.Interface( | |
| fn=tryon_api, | |
| inputs=[ | |
| gr.Image(type="filepath", label="Upload Your Selfie"), | |
| gr.Image(type="filepath", label="Upload Outfit Image") | |
| ], | |
| outputs="image", | |
| title="👗 Virtual Try-On", | |
| description="Try on clothes with your selfie and any outfit image." | |
| ) | |
| iface.launch() | |