Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
lixiang46
commited on
Commit
•
eaa8689
1
Parent(s):
fe775c6
add seed and encode
Browse files- app.py +12 -5
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,15 +1,21 @@
|
|
1 |
-
import sys
|
2 |
import os
|
3 |
-
import
|
4 |
from PIL import Image
|
5 |
import gradio as gr
|
6 |
import numpy as np
|
7 |
import random
|
|
|
8 |
|
9 |
|
10 |
-
def start_tryon(
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
return
|
13 |
|
14 |
MAX_SEED = 999999
|
15 |
|
@@ -59,6 +65,7 @@ with gr.Blocks(css=css) as Tryon:
|
|
59 |
examples=garm_list_path)
|
60 |
with gr.Column():
|
61 |
image_out = gr.Image(label="Output", show_share_button=False)
|
|
|
62 |
try_button = gr.Button(value="Try-on", elem_id="button")
|
63 |
|
64 |
|
@@ -73,6 +80,6 @@ with gr.Blocks(css=css) as Tryon:
|
|
73 |
)
|
74 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
75 |
|
76 |
-
try_button.click(fn=start_tryon, inputs=[imgs, garm_img, seed], outputs=[image_out], api_name='tryon')
|
77 |
|
78 |
Tryon.queue(max_size=10).launch()
|
|
|
|
|
1 |
import os
|
2 |
+
import cv2
|
3 |
from PIL import Image
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
import random
|
7 |
+
import base64
|
8 |
|
9 |
|
10 |
+
def start_tryon(person_img, garment_img, seed, randomize_seed):
|
11 |
+
if randomize_seed:
|
12 |
+
seed = random.randint(0, MAX_SEED)
|
13 |
+
encoded_person_img = cv2.imencode('.jpg', person_img)[1].tobytes()
|
14 |
+
encoded_person_img = base64.b64encode(encoded_person_img).decode('utf-8')
|
15 |
+
encoded_garment_img = cv2.imencode('.jpg', garment_img)[1].tobytes()
|
16 |
+
encoded_garment_img = base64.b64encode(encoded_garment_img).decode('utf-8')
|
17 |
|
18 |
+
return person_img, seed
|
19 |
|
20 |
MAX_SEED = 999999
|
21 |
|
|
|
65 |
examples=garm_list_path)
|
66 |
with gr.Column():
|
67 |
image_out = gr.Image(label="Output", show_share_button=False)
|
68 |
+
seed_used = gr.Number(label="Seed Used")
|
69 |
try_button = gr.Button(value="Try-on", elem_id="button")
|
70 |
|
71 |
|
|
|
80 |
)
|
81 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
82 |
|
83 |
+
try_button.click(fn=start_tryon, inputs=[imgs, garm_img, seed, randomize_seed], outputs=[image_out, seed_used], api_name='tryon')
|
84 |
|
85 |
Tryon.queue(max_size=10).launch()
|
requirements.txt
CHANGED
@@ -3,4 +3,5 @@ diffusers
|
|
3 |
invisible_watermark
|
4 |
torch
|
5 |
transformers
|
6 |
-
xformers
|
|
|
|
3 |
invisible_watermark
|
4 |
torch
|
5 |
transformers
|
6 |
+
xformers
|
7 |
+
opencv-python
|