Spaces:
Running
Running
add image preprocessing
Browse files- app.py +11 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import time
|
4 |
import requests
|
|
|
5 |
|
6 |
|
7 |
# ux format
|
@@ -67,6 +68,13 @@ def load_header(header_file):
|
|
67 |
content = f.read()
|
68 |
return content
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
def update_category(selected_garm_file):
|
71 |
selected_category = garm_img_category_mapping.get(os.path.basename(selected_garm_file), "Fullbody")
|
72 |
return gr.update(value=selected_category)
|
@@ -195,6 +203,9 @@ with gr.Blocks(css=tryon_css) as Huhu_Turbo:
|
|
195 |
inputs=[garm_img],
|
196 |
outputs=[category]
|
197 |
)
|
|
|
|
|
|
|
198 |
|
199 |
generate_button.click(fn=run_turbo, inputs=[person_img, garm_img, category], outputs=[result_img, result_info], api_name=False, concurrency_limit=30)
|
200 |
|
|
|
2 |
import os
|
3 |
import time
|
4 |
import requests
|
5 |
+
from PIL import Image
|
6 |
|
7 |
|
8 |
# ux format
|
|
|
68 |
content = f.read()
|
69 |
return content
|
70 |
|
71 |
+
def preprocess_img(img_path, max_size=1024):
|
72 |
+
img = Image.open(img_path)
|
73 |
+
if max(img.size) > max_size:
|
74 |
+
img.thumbnail((max_size, max_size))
|
75 |
+
img.save(img_path)
|
76 |
+
return img_path
|
77 |
+
|
78 |
def update_category(selected_garm_file):
|
79 |
selected_category = garm_img_category_mapping.get(os.path.basename(selected_garm_file), "Fullbody")
|
80 |
return gr.update(value=selected_category)
|
|
|
203 |
inputs=[garm_img],
|
204 |
outputs=[category]
|
205 |
)
|
206 |
+
|
207 |
+
garm_img.change(fn=preprocess_img, inputs=[garm_img], outputs=[garm_img])
|
208 |
+
person_img.change(fn=preprocess_img, inputs=[person_img], outputs=[person_img])
|
209 |
|
210 |
generate_button.click(fn=run_turbo, inputs=[person_img, garm_img, category], outputs=[result_img, result_info], api_name=False, concurrency_limit=30)
|
211 |
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Pillow
|