Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,30 @@ import json
|
|
| 10 |
API_KEY = 'N80HWHVG3DV8URRNYZY382UPSHP1N8G1SNPYG0E9'
|
| 11 |
API_URL = 'https://api.runpod.ai/v2/31jyh9kh7nwyga'
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def get_base64_from_url(url):
|
| 16 |
response = requests.get(url)
|
|
@@ -38,21 +61,13 @@ def generate_tryon(cloth_input, user_input, background):
|
|
| 38 |
"background": background
|
| 39 |
}
|
| 40 |
|
| 41 |
-
# Prepare log message
|
| 42 |
-
log_data = {
|
| 43 |
-
"user_image": user_base64[:20] + '...' if user_base64 else 'undefined',
|
| 44 |
-
"product_image": cloth_base64[:20] + '...' if cloth_base64 else 'undefined',
|
| 45 |
-
"background": background,
|
| 46 |
-
}
|
| 47 |
-
log_message = f"Sending data:\n{json.dumps(log_data, indent=2)}"
|
| 48 |
-
|
| 49 |
response = requests.post(
|
| 50 |
f"{API_URL}/run",
|
| 51 |
headers={
|
| 52 |
"Authorization": f"Bearer {API_KEY}",
|
| 53 |
"Content-Type": "application/json"
|
| 54 |
},
|
| 55 |
-
|
| 56 |
)
|
| 57 |
|
| 58 |
if not response.ok:
|
|
@@ -74,7 +89,7 @@ def generate_tryon(cloth_input, user_input, background):
|
|
| 74 |
if status_data['status'] == 'COMPLETED':
|
| 75 |
output_base64 = status_data['output']['output']
|
| 76 |
output_image = Image.open(io.BytesIO(base64.b64decode(output_base64)))
|
| 77 |
-
return output_image
|
| 78 |
elif status_data['status'] == 'FAILED':
|
| 79 |
raise Exception(f"Job processing failed: {status_data}")
|
| 80 |
|
|
@@ -86,17 +101,17 @@ def tryon_interface(cloth_selected, cloth_upload, user_selected, user_upload, sc
|
|
| 86 |
background = custom_scene if custom_scene else scene_selection
|
| 87 |
|
| 88 |
if not cloth:
|
| 89 |
-
return None, "Please select or upload a clothing image."
|
| 90 |
if not user:
|
| 91 |
-
return None, "Please select or upload a user image."
|
| 92 |
if not background:
|
| 93 |
-
return None, "Please select or enter a background scene."
|
| 94 |
|
| 95 |
try:
|
| 96 |
-
result_image
|
| 97 |
-
return result_image, "Try-on image generated successfully!"
|
| 98 |
except Exception as e:
|
| 99 |
-
return None, f"Error: {str(e)}"
|
| 100 |
|
| 101 |
def select_image(evt: gr.SelectData, image_list):
|
| 102 |
if evt.index < len(image_list):
|
|
@@ -137,7 +152,6 @@ with gr.Blocks() as demo:
|
|
| 137 |
|
| 138 |
output_image = gr.Image(label="Try-On Result")
|
| 139 |
output_text = gr.Textbox(label="Status")
|
| 140 |
-
log_output = gr.Textbox(label="API Request Details", lines=10)
|
| 141 |
|
| 142 |
cloth_gallery.select(
|
| 143 |
fn=lambda evt: select_image(evt, cloth_images),
|
|
@@ -154,7 +168,7 @@ with gr.Blocks() as demo:
|
|
| 154 |
generate_button.click(
|
| 155 |
tryon_interface,
|
| 156 |
inputs=[cloth_selected, cloth_upload, user_selected, user_upload, scene_selection, custom_scene],
|
| 157 |
-
outputs=[output_image, output_text
|
| 158 |
)
|
| 159 |
|
| 160 |
demo.launch()
|
|
|
|
| 10 |
API_KEY = 'N80HWHVG3DV8URRNYZY382UPSHP1N8G1SNPYG0E9'
|
| 11 |
API_URL = 'https://api.runpod.ai/v2/31jyh9kh7nwyga'
|
| 12 |
|
| 13 |
+
cloth_images = [
|
| 14 |
+
{"url": "https://i.postimg.cc/7ZzLZtbc/hmgoepprod-4-1.jpg", "label": "Jacket 1"},
|
| 15 |
+
{"url": "https://i.postimg.cc/7Yd6DrP0/hmgoepprod-6.jpg", "label": "Jacket 2"},
|
| 16 |
+
{"url": "https://i.postimg.cc/8z40MNFr/hnm.png", "label": "Jacket 3"},
|
| 17 |
+
{"url": "https://i.postimg.cc/mkqbb74B/hmgoepprod-5.jpg", "label": "Jacket 4"},
|
| 18 |
+
{"url": "https://i.postimg.cc/vBwySGzH/hmgoepprod.jpg", "label": "Jacket 5"},
|
| 19 |
+
{"url": "https://i.postimg.cc/6qSYYprM/Whats-App-Image-2024-08-18-at-13-45-37-2.jpg", "label": "Jacket 6"},
|
| 20 |
+
{"url": "https://i.postimg.cc/tJHhTnzQ/Screenshot-2024-08-20-at-10-04-29-PM.png", "label": "Jacket 7"},
|
| 21 |
+
{"url": "https://i.postimg.cc/yxQYGwxQ/Screenshot-2024-08-20-at-10-06-28-PM.png", "label": "Jacket 8"},
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
user_images = [
|
| 25 |
+
{"url": "https://iili.io/dEk7qtp.md.jpg", "label": "User 1 (Male)"},
|
| 26 |
+
{"url": "https://iili.io/d1RpKBa.md.jpg", "label": "User 2 (Female)"},
|
| 27 |
+
{"url": "https://i.postimg.cc/QtzQrnFt/Whats-App-Image-2024-08-18-at-13-42-10.jpg", "label": "User 3 (Female)"},
|
| 28 |
+
{"url": "https://i.postimg.cc/rsKLDzyj/Whats-App-Image-2024-08-19-at-12-13-41.jpg", "label": "User 4 (Female)"},
|
| 29 |
+
{"url": "https://i.postimg.cc/cHkpGZ7n/Whats-App-Image-2024-08-19-at-00-27-16-1.jpg", "label": "User 5 (Female)"},
|
| 30 |
+
{"url": "https://i.postimg.cc/g2bfWghN/Whats-App-Image-2024-08-19-at-12-13-41-1.jpg", "label": "User 6 (Female)"},
|
| 31 |
+
]
|
| 32 |
+
|
| 33 |
+
scene_options = [
|
| 34 |
+
"Gym", "City Street", "Party", "Beach", "Office", "Park", "Cafe",
|
| 35 |
+
"Shopping Mall", "Concert", "Sports Stadium"
|
| 36 |
+
]
|
| 37 |
|
| 38 |
def get_base64_from_url(url):
|
| 39 |
response = requests.get(url)
|
|
|
|
| 61 |
"background": background
|
| 62 |
}
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
response = requests.post(
|
| 65 |
f"{API_URL}/run",
|
| 66 |
headers={
|
| 67 |
"Authorization": f"Bearer {API_KEY}",
|
| 68 |
"Content-Type": "application/json"
|
| 69 |
},
|
| 70 |
+
data=json.dumps({"input": input_data})
|
| 71 |
)
|
| 72 |
|
| 73 |
if not response.ok:
|
|
|
|
| 89 |
if status_data['status'] == 'COMPLETED':
|
| 90 |
output_base64 = status_data['output']['output']
|
| 91 |
output_image = Image.open(io.BytesIO(base64.b64decode(output_base64)))
|
| 92 |
+
return output_image
|
| 93 |
elif status_data['status'] == 'FAILED':
|
| 94 |
raise Exception(f"Job processing failed: {status_data}")
|
| 95 |
|
|
|
|
| 101 |
background = custom_scene if custom_scene else scene_selection
|
| 102 |
|
| 103 |
if not cloth:
|
| 104 |
+
return None, "Please select or upload a clothing image."
|
| 105 |
if not user:
|
| 106 |
+
return None, "Please select or upload a user image."
|
| 107 |
if not background:
|
| 108 |
+
return None, "Please select or enter a background scene."
|
| 109 |
|
| 110 |
try:
|
| 111 |
+
result_image = generate_tryon(cloth, user, background)
|
| 112 |
+
return result_image, "Try-on image generated successfully!"
|
| 113 |
except Exception as e:
|
| 114 |
+
return None, f"Error: {str(e)}"
|
| 115 |
|
| 116 |
def select_image(evt: gr.SelectData, image_list):
|
| 117 |
if evt.index < len(image_list):
|
|
|
|
| 152 |
|
| 153 |
output_image = gr.Image(label="Try-On Result")
|
| 154 |
output_text = gr.Textbox(label="Status")
|
|
|
|
| 155 |
|
| 156 |
cloth_gallery.select(
|
| 157 |
fn=lambda evt: select_image(evt, cloth_images),
|
|
|
|
| 168 |
generate_button.click(
|
| 169 |
tryon_interface,
|
| 170 |
inputs=[cloth_selected, cloth_upload, user_selected, user_upload, scene_selection, custom_scene],
|
| 171 |
+
outputs=[output_image, output_text]
|
| 172 |
)
|
| 173 |
|
| 174 |
demo.launch()
|