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

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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 = {
9
+ "X-RapidAPI-Key": os.getenv("RAPIDAPI_KEY"),
10
+ "X-RapidAPI-Host": "tryon-diffusion.p.rapidapi.com"
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()