File size: 1,884 Bytes
b021ace
 
 
3a1adec
b021ace
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b56c75
 
 
 
 
 
 
 
 
 
 
 
 
b021ace
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import subprocess
import shutil
import os
import gradio as gr
import torchvision.transforms as T
import spaces

subprocess.run(["git", "clone", "https://github.com/AIRI-Institute/HairFastGAN"], check=True)
os.chdir("HairFastGAN")

subprocess.run(["git", "clone", "https://huggingface.co/AIRI-Institute/HairFastGAN"], check=True)

os.chdir("HairFastGAN")
subprocess.run(["git", "lfs", "pull"], check=True)
os.chdir("..")

shutil.move("HairFastGAN/pretrained_models", "pretrained_models")
shutil.move("HairFastGAN/input", "input")

shutil.rmtree("HairFastGAN")

directory_path = 'pretrained_models'
# Iterate over each entry in the directory
for entry in os.listdir(directory_path):
    # Create full path to the entry
    full_path = os.path.join(directory_path, entry)
    # Check if it's a file
    if os.path.isfile(full_path):
        # Get the file size
        size = os.path.getsize(full_path)
        # Print file name and its size in bytes
        print(f"{entry}: {size} bytes")

from HairFastGAN.hair_swap import HairFast, get_parser

hair_fast = HairFast(get_parser().parse_args([]))

@spaces.GPU
def swap_hair(source, target_1, target_2):
    result = hair_fast(face_img, shape_img, color_img)
    final_image = hair_fast.swap(face_path, shape_path, color_path)
    return T.functional.to_pil_image(final_image)
    
with gr.Blocks() as demo:
    gr.Markdown("Start typing below and then click **Run** to see the output.")
    with gr.Row():
        source = gr.Image(label="Photo that you want to replace the hair", type="filepath")
        target_1 = gr.Image(label="Reference hair you want to get", type="filepath")
        target_2 = gr.Image(label="Reference color hair you want to get (optional)", type="filepath")
    btn = gr.Button("Get the haircut")
    output = gr.Image(label="Your result")
    
    btn.click(fn=update, inputs=inp, outputs=out)

demo.launch()