Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,20 @@ from themes import IndonesiaTheme # Impor tema custom dari themes.py
|
|
5 |
from PIL import Image
|
6 |
import random
|
7 |
import tempfile # Untuk membuat file sementara
|
|
|
8 |
|
9 |
-
# Siapkan URL
|
10 |
url_api = os.environ['url_api']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
# Fungsi untuk menyimpan gambar sementara ke file
|
13 |
def save_temp_image(image_array):
|
@@ -18,7 +29,10 @@ def save_temp_image(image_array):
|
|
18 |
|
19 |
# Fungsi untuk memanggil API Virtual Try-On
|
20 |
def virtual_tryon(person_img, garment_img, garment_des, seed, randomize_seed, denoise_steps, is_checked, is_checked_crop):
|
21 |
-
|
|
|
|
|
|
|
22 |
|
23 |
# Simpan gambar sementara
|
24 |
person_img_path = save_temp_image(person_img)
|
@@ -56,11 +70,16 @@ def virtual_tryon(person_img, garment_img, garment_des, seed, randomize_seed, de
|
|
56 |
"Gaya Anda sangat menakjubkan dengan pakaian ini!",
|
57 |
"Perfect match! Anda terlihat menawan!",
|
58 |
"Siap untuk sesi foto? Anda benar-benar keren!"
|
59 |
-
|
60 |
|
61 |
-
#
|
62 |
return result[0], random.choice(compliments), "Proses selesai."
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
# Path untuk contoh gambar
|
65 |
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|
66 |
|
@@ -72,7 +91,6 @@ garm_list_path = [os.path.join(example_path, "cloth", garm) for garm in garm_lis
|
|
72 |
human_list = os.listdir(os.path.join(example_path, "human"))
|
73 |
human_list_path = [os.path.join(example_path, "human", human) for human in human_list]
|
74 |
|
75 |
-
|
76 |
# CSS untuk styling antarmuka
|
77 |
css = """
|
78 |
#col-left, #col-mid, #col-right {
|
@@ -131,6 +149,7 @@ with gr.Blocks(css=css, theme=IndonesiaTheme()) as TokoBajuVirtual:
|
|
131 |
gr.Examples(inputs=garment_img, examples=garm_list_path, examples_per_page=14)
|
132 |
|
133 |
with gr.Column(elem_id="col-right"):
|
|
|
134 |
result_img = gr.Image(label="Hasil", show_share_button=False)
|
135 |
seed = gr.Slider(label="Token-Slider", minimum=0, maximum=999999, step=1, value=42)
|
136 |
randomize_seed = gr.Checkbox(label="Random Token", value=True)
|
@@ -144,7 +163,13 @@ with gr.Blocks(css=css, theme=IndonesiaTheme()) as TokoBajuVirtual:
|
|
144 |
run_button.click(
|
145 |
fn=virtual_tryon,
|
146 |
inputs=[person_img, garment_img, garment_des, seed, randomize_seed, denoise_steps, is_checked, is_checked_crop],
|
147 |
-
outputs=[result_img, result_info]
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
)
|
149 |
|
150 |
# Tambahkan footer di bagian bawah
|
|
|
5 |
from PIL import Image
|
6 |
import random
|
7 |
import tempfile # Untuk membuat file sementara
|
8 |
+
import time # Untuk fungsi penundaan
|
9 |
|
10 |
+
# Siapkan URL untuk permintaan API Virtual Try-On
|
11 |
url_api = os.environ['url_api']
|
12 |
+
url_api2 = os.environ['url_api2']
|
13 |
+
url_api3 = os.environ['url_api3']
|
14 |
+
url_api4 = os.environ['url_api4']
|
15 |
+
url_api5 = os.environ['url_api5']
|
16 |
+
url_api6 = os.environ['url_api6']
|
17 |
+
url_api7 = os.environ['url_api7']
|
18 |
+
|
19 |
+
# Fungsi untuk memilih URL secara acak
|
20 |
+
def get_random_api_url():
|
21 |
+
return random.choice([url_api, url_api2, url_api3, url_api4, url_api5, url_api6, url_api7])
|
22 |
|
23 |
# Fungsi untuk menyimpan gambar sementara ke file
|
24 |
def save_temp_image(image_array):
|
|
|
29 |
|
30 |
# Fungsi untuk memanggil API Virtual Try-On
|
31 |
def virtual_tryon(person_img, garment_img, garment_des, seed, randomize_seed, denoise_steps, is_checked, is_checked_crop):
|
32 |
+
|
33 |
+
# Pilih URL secara acak
|
34 |
+
selected_api_url = get_random_api_url()
|
35 |
+
client = Client(selected_api_url)
|
36 |
|
37 |
# Simpan gambar sementara
|
38 |
person_img_path = save_temp_image(person_img)
|
|
|
70 |
"Gaya Anda sangat menakjubkan dengan pakaian ini!",
|
71 |
"Perfect match! Anda terlihat menawan!",
|
72 |
"Siap untuk sesi foto? Anda benar-benar keren!"
|
73 |
+
]
|
74 |
|
75 |
+
# Mengembalikan hasil dan pesan pujian acak
|
76 |
return result[0], random.choice(compliments), "Proses selesai."
|
77 |
|
78 |
+
# Fungsi untuk menampilkan pesan popup dan menunda eksekusi
|
79 |
+
def show_popup_and_wait():
|
80 |
+
gr.alert("Ruang ganti kami terbatas. Mohon menunggu antreannya.")
|
81 |
+
time.sleep(60) # Menunggu selama 1 menit
|
82 |
+
|
83 |
# Path untuk contoh gambar
|
84 |
example_path = os.path.join(os.path.dirname(__file__), 'assets')
|
85 |
|
|
|
91 |
human_list = os.listdir(os.path.join(example_path, "human"))
|
92 |
human_list_path = [os.path.join(example_path, "human", human) for human in human_list]
|
93 |
|
|
|
94 |
# CSS untuk styling antarmuka
|
95 |
css = """
|
96 |
#col-left, #col-mid, #col-right {
|
|
|
149 |
gr.Examples(inputs=garment_img, examples=garm_list_path, examples_per_page=14)
|
150 |
|
151 |
with gr.Column(elem_id="col-right"):
|
152 |
+
gr.Markdown("### Ruang Ganti Umum")
|
153 |
result_img = gr.Image(label="Hasil", show_share_button=False)
|
154 |
seed = gr.Slider(label="Token-Slider", minimum=0, maximum=999999, step=1, value=42)
|
155 |
randomize_seed = gr.Checkbox(label="Random Token", value=True)
|
|
|
163 |
run_button.click(
|
164 |
fn=virtual_tryon,
|
165 |
inputs=[person_img, garment_img, garment_des, seed, randomize_seed, denoise_steps, is_checked, is_checked_crop],
|
166 |
+
outputs=[result_img, result_info]
|
167 |
+
)
|
168 |
+
# Tambahkan penundaan setelah klik dan pesan popup
|
169 |
+
run_button.click(
|
170 |
+
fn=show_popup_and_wait, # Menampilkan popup dan menunda eksekusi
|
171 |
+
inputs=[],
|
172 |
+
outputs=[]
|
173 |
)
|
174 |
|
175 |
# Tambahkan footer di bagian bawah
|