Spaces:
Sleeping
Sleeping
File size: 1,061 Bytes
27e704b fdb5009 27e704b fdb5009 27e704b fdb5009 27e704b fdb5009 27e704b fdb5009 27e704b fdb5009 27e704b fdb5009 27e704b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 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()
|