fffiloni commited on
Commit
8eb20e0
1 Parent(s): d707478

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -9
app.py CHANGED
@@ -1,13 +1,30 @@
1
  import gradio as gr
2
  import subprocess
3
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def generate(image, prompt, seed):
6
  print(image, prompt, seed)
7
  image_path = os.path.splitext(image)[0]
8
  image_name = os.path.basename(image_path)
 
 
9
  print(f"IMAGE NAME: {image_name}")
10
- command = f"python handrefiner.py --input_img {image} --out_dir output --strength 0.55 --weights models/inpaint_depth_control.ckpt --prompt '{prompt}' --seed {seed}"
11
  try:
12
  result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
13
  output_path = 'output'
@@ -25,15 +42,27 @@ def generate(image, prompt, seed):
25
  print("Error:", e.stderr)
26
  return None
27
 
 
 
 
 
 
 
28
  with gr.Blocks() as demo:
29
- with gr.Row():
30
- with gr.Column():
31
- image = gr.Image(type='filepath')
32
- textbox = gr.Textbox(show_label=False, value="a person facing the camera, making a hand gesture, indoor")
33
- seed = gr.Slider(minimum=0, maximum=1000000, value=643534)
34
- button = gr.Button()
35
- output_image = gr.Image(show_label=False, type="filepath", interactive=False, height=512, width=512)
36
- #output_image = gr.Textbox()
 
 
 
 
 
 
37
  button.click(fn=generate, inputs=[image, textbox, seed], outputs=[output_image])
38
 
39
  demo.queue().launch(inline=False, share=True, debug=True)
 
1
  import gradio as gr
2
  import subprocess
3
  import os
4
+ from PIL import Image
5
+
6
+ def resize_image(image_path, target_height, output_path):
7
+ # Open the image file
8
+ with Image.open(image_path) as img:
9
+ # Calculate the ratio to resize the image to the target height
10
+ ratio = target_height / float(img.size[1])
11
+ # Calculate the new width based on the aspect ratio
12
+ new_width = int(float(img.size[0]) * ratio)
13
+ # Resize the image
14
+ resized_img = img.resize((new_width, target_height), Image.LANCZOS)
15
+ # Save the resized image
16
+ resized_img.save(output_path)
17
+ return resized_img
18
+
19
 
20
  def generate(image, prompt, seed):
21
  print(image, prompt, seed)
22
  image_path = os.path.splitext(image)[0]
23
  image_name = os.path.basename(image_path)
24
+
25
+ resized=resize_image(image, 512, f"output/{image_name}.jpg")
26
  print(f"IMAGE NAME: {image_name}")
27
+ command = f"python handrefiner.py --input_img {resized} --out_dir output --strength 0.55 --weights models/inpaint_depth_control.ckpt --prompt '{prompt}' --seed {seed}"
28
  try:
29
  result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
30
  output_path = 'output'
 
42
  print("Error:", e.stderr)
43
  return None
44
 
45
+ css="""
46
+ #col-container{
47
+ max-width: 860px;
48
+ margin: 0 auto;
49
+ }
50
+ """
51
  with gr.Blocks() as demo:
52
+ with gr.Column(elem_id="col-container"):
53
+ gr.HTML("""
54
+ <h2 style="text-aligb: center;">
55
+ HandRefiner
56
+ </h2>
57
+ """)
58
+ with gr.Row():
59
+ with gr.Column():
60
+ image = gr.Image(type='filepath')
61
+ textbox = gr.Textbox(show_label=False, value="a person facing the camera, making a hand gesture, indoor")
62
+ seed = gr.Slider(label="Seed", minimum=0, maximum=1000000, value=643534)
63
+ button = gr.Button()
64
+ output_image = gr.Image(show_label=False, type="filepath", interactive=False, height=512, width=512)
65
+
66
  button.click(fn=generate, inputs=[image, textbox, seed], outputs=[output_image])
67
 
68
  demo.queue().launch(inline=False, share=True, debug=True)