hysts HF staff commited on
Commit
16ea01f
1 Parent(s): bf742c5
Files changed (1) hide show
  1. app.py +42 -20
app.py CHANGED
@@ -4,10 +4,12 @@ from __future__ import annotations
4
 
5
  import os
6
  import pathlib
 
7
  import shlex
8
  import subprocess
9
 
10
  import gradio as gr
 
11
 
12
  if os.getenv('SYSTEM') == 'spaces':
13
  import mim
@@ -27,6 +29,15 @@ You can modify sample steps and seeds. By varying seeds, you can sample differen
27
  Label image generation step can be skipped. However, in that case, the input label image must be 512x256 in size and must contain only the specified colors.
28
  '''
29
 
 
 
 
 
 
 
 
 
 
30
  model = Model()
31
 
32
  with gr.Blocks(css='style.css') as demo:
@@ -81,14 +92,16 @@ Note: Currently, only 5 types of textures are supported, i.e., pure color, strip
81
  sample_steps = gr.Slider(label='Sample Steps',
82
  minimum=10,
83
  maximum=300,
84
- step=10,
85
- value=10)
86
  with gr.Row():
87
  seed = gr.Slider(label='Seed',
88
  minimum=0,
89
- maximum=1000000,
90
  step=1,
91
  value=0)
 
 
92
  with gr.Row():
93
  generate_human_button = gr.Button('Generate Human')
94
 
@@ -98,21 +111,30 @@ Note: Currently, only 5 types of textures are supported, i.e., pure color, strip
98
  type='numpy',
99
  elem_id='result-image')
100
 
101
- input_image.change(fn=model.process_pose_image,
102
- inputs=input_image,
103
- outputs=pose_data)
104
- generate_label_button.click(fn=model.generate_label_image,
105
- inputs=[
106
- pose_data,
107
- shape_text,
108
- ],
109
- outputs=label_image)
110
- generate_human_button.click(fn=model.generate_human,
111
- inputs=[
112
- label_image,
113
- texture_text,
114
- sample_steps,
115
- seed,
116
- ],
117
- outputs=result)
 
 
 
 
 
 
 
 
 
118
  demo.queue(max_size=10).launch()
 
4
 
5
  import os
6
  import pathlib
7
+ import random
8
  import shlex
9
  import subprocess
10
 
11
  import gradio as gr
12
+ import numpy as np
13
 
14
  if os.getenv('SYSTEM') == 'spaces':
15
  import mim
 
29
  Label image generation step can be skipped. However, in that case, the input label image must be 512x256 in size and must contain only the specified colors.
30
  '''
31
 
32
+ MAX_SEED = np.iinfo(np.int32).max
33
+
34
+
35
+ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
36
+ if randomize_seed:
37
+ seed = random.randint(0, MAX_SEED)
38
+ return seed
39
+
40
+
41
  model = Model()
42
 
43
  with gr.Blocks(css='style.css') as demo:
 
92
  sample_steps = gr.Slider(label='Sample Steps',
93
  minimum=10,
94
  maximum=300,
95
+ step=1,
96
+ value=256)
97
  with gr.Row():
98
  seed = gr.Slider(label='Seed',
99
  minimum=0,
100
+ maximum=MAX_SEED,
101
  step=1,
102
  value=0)
103
+ randomize_seed = gr.Checkbox(label='Randomize seed',
104
+ value=True)
105
  with gr.Row():
106
  generate_human_button = gr.Button('Generate Human')
107
 
 
111
  type='numpy',
112
  elem_id='result-image')
113
 
114
+ input_image.change(
115
+ fn=model.process_pose_image,
116
+ inputs=input_image,
117
+ outputs=pose_data,
118
+ )
119
+ generate_label_button.click(
120
+ fn=model.generate_label_image,
121
+ inputs=[
122
+ pose_data,
123
+ shape_text,
124
+ ],
125
+ outputs=label_image,
126
+ )
127
+ generate_human_button.click(fn=randomize_seed_fn,
128
+ inputs=[seed, randomize_seed],
129
+ outputs=seed,
130
+ queue=False).then(
131
+ fn=model.generate_human,
132
+ inputs=[
133
+ label_image,
134
+ texture_text,
135
+ sample_steps,
136
+ seed,
137
+ ],
138
+ outputs=result,
139
+ )
140
  demo.queue(max_size=10).launch()