Virtualtryon / app.py
Aaronjf97's picture
Update app.py
fdb5009 verified
Raw History Blame Contribute Delete
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()