Aaronjf97 commited on
Commit
fdb5009
·
verified ·
1 Parent(s): 27e704b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import requests
3
  import os
4
 
5
- def tryon_api(selfie, outfit):
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", selfie, "image/jpeg"),
15
- "cloth_image": ("outfit.jpg", outfit, "image/jpeg")
16
  }
17
 
18
  response = requests.post(url, headers=headers, files=files)
19
 
20
  try:
21
- output = response.json()
22
- return output.get("output_url", "No output image returned")
23
  except:
24
- return "Error occurred during try-on."
25
 
26
- # Build Gradio UI
27
  iface = gr.Interface(
28
  fn=tryon_api,
29
  inputs=[
30
- gr.Image(type="file", label="Upload Your Selfie"),
31
- gr.Image(type="file", label="Upload Outfit Image")
32
  ],
33
  outputs="image",
34
- title="👕 Virtual Try-On with AI",
35
- description="Upload your selfie and outfit image to see the AI try-on result."
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()