Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
def tryon_api(
|
| 6 |
url = "https://tryon-diffusion.p.rapidapi.com/try-on-file"
|
| 7 |
|
| 8 |
headers = {
|
|
@@ -11,28 +11,28 @@ def tryon_api(selfie, outfit):
|
|
| 11 |
}
|
| 12 |
|
| 13 |
files = {
|
| 14 |
-
"person_image": ("selfie.jpg",
|
| 15 |
-
"cloth_image": ("outfit.jpg",
|
| 16 |
}
|
| 17 |
|
| 18 |
response = requests.post(url, headers=headers, files=files)
|
| 19 |
|
| 20 |
try:
|
| 21 |
-
|
| 22 |
-
return
|
| 23 |
except:
|
| 24 |
-
return "Error
|
| 25 |
|
| 26 |
-
#
|
| 27 |
iface = gr.Interface(
|
| 28 |
fn=tryon_api,
|
| 29 |
inputs=[
|
| 30 |
-
gr.Image(type="
|
| 31 |
-
gr.Image(type="
|
| 32 |
],
|
| 33 |
outputs="image",
|
| 34 |
-
title="
|
| 35 |
-
description="
|
| 36 |
)
|
| 37 |
|
| 38 |
iface.launch()
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
def tryon_api(selfie_path, outfit_path):
|
| 6 |
url = "https://tryon-diffusion.p.rapidapi.com/try-on-file"
|
| 7 |
|
| 8 |
headers = {
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
files = {
|
| 14 |
+
"person_image": ("selfie.jpg", open(selfie_path, "rb"), "image/jpeg"),
|
| 15 |
+
"cloth_image": ("outfit.jpg", open(outfit_path, "rb"), "image/jpeg")
|
| 16 |
}
|
| 17 |
|
| 18 |
response = requests.post(url, headers=headers, files=files)
|
| 19 |
|
| 20 |
try:
|
| 21 |
+
result = response.json()
|
| 22 |
+
return result.get("output_url", "No image returned.")
|
| 23 |
except:
|
| 24 |
+
return "Error: API failed."
|
| 25 |
|
| 26 |
+
# 🟢 FIXED: type='filepath' instead of 'file'
|
| 27 |
iface = gr.Interface(
|
| 28 |
fn=tryon_api,
|
| 29 |
inputs=[
|
| 30 |
+
gr.Image(type="filepath", label="Upload Your Selfie"),
|
| 31 |
+
gr.Image(type="filepath", label="Upload Outfit Image")
|
| 32 |
],
|
| 33 |
outputs="image",
|
| 34 |
+
title="👗 Virtual Try-On",
|
| 35 |
+
description="Try on clothes with your selfie and any outfit image."
|
| 36 |
)
|
| 37 |
|
| 38 |
iface.launch()
|