|
import os |
|
import io |
|
|
|
import PIL.Image |
|
import gradio as gr |
|
from gradio_client import Client, handle_file |
|
|
|
from gradio_client.client import re |
|
from numpy import array |
|
|
|
HF_TOKEN = os.getenv("HF_TOKEN") |
|
|
|
|
|
client = Client( |
|
"franciszzj/Leffa", |
|
hf_token=HF_TOKEN, |
|
) |
|
|
|
|
|
def virtual_tryon( |
|
person_path, |
|
garment_path, |
|
garment_type, |
|
): |
|
|
|
person_file = handle_file( |
|
person_path |
|
) |
|
garment_file = handle_file(garment_path) |
|
|
|
|
|
|
|
|
|
result = client.predict( |
|
person_file, |
|
garment_file, |
|
ref_acceleration=False, |
|
step=30, |
|
scale=2.5, |
|
seed=42, |
|
vt_model_type="viton_hd", |
|
vt_garment_type=garment_type, |
|
vt_repaint=False, |
|
api_name="/leffa_predict_vt",) |
|
|
|
return result[0] |
|
|
|
|
|
|
|
|
|
with gr.Blocks(theme=gr.themes.Soft()) as demo: |
|
gr.Markdown("") |
|
with gr.Row(): |
|
with gr.Column(): |
|
gr.Markdown("") |
|
src = gr.Image(sources="upload", type="filepath", |
|
label="Foto e personit") |
|
with gr.Column(): |
|
gr.Markdown("") |
|
ref = gr.Image(sources="upload", type="filepath", |
|
label="Foto e veshjes") |
|
with gr.Column(): |
|
gr.Markdown("") |
|
garment_type = gr.Radio( |
|
choices=[("Siper", "upper_body"), |
|
("Posht", "lower_body"), ("Komplet", "dresses")], |
|
value="upper_body", |
|
label="Lloji i veshjes", |
|
) |
|
with gr.Column(): |
|
gr.Markdown("") |
|
out = gr.Image(type="filepath", label="Rezultati",) |
|
with gr.Row(): |
|
btn = gr.Button("VISHU") |
|
|
|
btn.click(virtual_tryon, [src, ref, garment_type], out) |
|
|
|
demo.launch( |
|
share=True, |
|
show_error=True, |
|
pwa=True, |
|
) |
|
|
|
|