File size: 2,516 Bytes
4045a73
 
865ddb0
8eb20e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4045a73
 
 
d707478
 
8eb20e0
 
22e427c
8eb20e0
4045a73
 
1688517
4045a73
aad4b49
ef9c3f5
5a5aa5d
ef9c3f5
 
 
 
 
8cbbe53
4045a73
 
 
 
8eb20e0
 
 
 
 
 
4045a73
8eb20e0
 
 
 
 
 
 
 
 
 
 
 
 
 
4045a73
 
 
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
56
57
58
59
60
61
62
63
64
65
66
67
68
import gradio as gr
import subprocess
import os
from PIL import Image

def resize_image(image_path, target_height, output_path):
    # Open the image file
    with Image.open(image_path) as img:
        # Calculate the ratio to resize the image to the target height
        ratio = target_height / float(img.size[1])
        # Calculate the new width based on the aspect ratio
        new_width = int(float(img.size[0]) * ratio)
        # Resize the image
        resized_img = img.resize((new_width, target_height), Image.LANCZOS)
        # Save the resized image
        resized_img.save(output_path)
        return resized_img


def generate(image, prompt, seed):
    print(image, prompt, seed)
    image_path = os.path.splitext(image)[0]
    image_name = os.path.basename(image_path)

    resized=resize_image(image, 512, f"output/{image_name}.jpg")
    print(f"IMAGE NAME: {image_name}")
    command = f"python handrefiner.py --input_img {resized} --out_dir output --strength 0.55 --weights models/inpaint_depth_control.ckpt --prompt '{prompt}' --seed {seed}"
    try:
        result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
        output_path = 'output'
        print("Output:", result.stdout)
        print(output_path)
        # List all files and directories in the given directory
        contents = os.listdir("output")
        
        # Print the contents
        for item in contents:
            print(item)
        
        return f"output/{image_name}_0.jpg"
    except subprocess.CalledProcessError as e:
        print("Error:", e.stderr)
        return None

css="""
#col-container{
    max-width: 860px;
    margin: 0 auto;
}
"""
with gr.Blocks() as demo:
    with gr.Column(elem_id="col-container"):
        gr.HTML("""
        <h2 style="text-aligb: center;">
            HandRefiner
        </h2>
        """)
        with gr.Row():
            with gr.Column():
                image = gr.Image(type='filepath')
                textbox = gr.Textbox(show_label=False, value="a person facing the camera, making a hand gesture, indoor")
                seed = gr.Slider(label="Seed", minimum=0, maximum=1000000, value=643534)
                button = gr.Button()
            output_image = gr.Image(show_label=False, type="filepath", interactive=False, height=512, width=512)
      
    button.click(fn=generate, inputs=[image, textbox, seed], outputs=[output_image])

demo.queue().launch(inline=False, share=True, debug=True)