fffiloni commited on
Commit
a27478b
1 Parent(s): 9ea6812

UI refactored

Browse files
Files changed (1) hide show
  1. app.py +106 -87
app.py CHANGED
@@ -6,6 +6,9 @@ import os
6
 
7
  from utils.gradio_helpers import parse_outputs, process_outputs
8
 
 
 
 
9
  names = ['image', 'rotate_pitch', 'rotate_yaw', 'rotate_roll', 'blink', 'eyebrow', 'wink', 'pupil_x', 'pupil_y', 'aaa', 'eee', 'woo', 'smile', 'src_ratio', 'sample_ratio', 'crop_factor', 'output_format', 'output_quality']
10
 
11
  def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
@@ -62,111 +65,127 @@ with gr.Blocks() as demo:
62
  type="filepath",
63
  height=180
64
  )
65
- with gr.Row():
66
- rotate_pitch = gr.Slider(
67
- label="Rotate Up-Down",
68
- value=0,
69
- minimum=-20, maximum=20
70
- )
71
- rotate_yaw = gr.Slider(
72
- label="Rotate Left-Right turn",
73
- value=0,
74
- minimum=-20, maximum=20
75
- )
76
- rotate_roll = gr.Slider(
77
- label="Rotate Left-Right tilt", value=0,
78
- minimum=-20, maximum=20
79
- )
80
- with gr.Row():
81
- blink = gr.Slider(
82
- label="Blink", value=0,
83
- minimum=-20, maximum=5
84
- )
85
- eyebrow = gr.Slider(
86
- label="Eyebrow", value=0,
87
- minimum=-10, maximum=15
88
- )
89
- wink = gr.Slider(
90
- label="Wink", value=0,
91
- minimum=0, maximum=25
92
- )
93
- with gr.Row():
94
- pupil_x = gr.Slider(
95
- label="Pupil X", value=0,
96
- minimum=-15, maximum=15
97
- )
98
- pupil_y = gr.Slider(
99
- label="Pupil Y", value=0,
100
- minimum=-15, maximum=15
101
- )
102
- with gr.Row():
103
- aaa = gr.Slider(
104
- label="Aaa", value=0,
105
- minimum=-30, maximum=120
106
- )
107
- eee = gr.Slider(
108
- label="Eee", value=0,
109
- minimum=-20, maximum=15
110
- )
111
- woo = gr.Slider(
112
- label="Woo", value=0,
113
- minimum=-20, maximum=15
114
- )
115
- smile = gr.Slider(
116
- label="Smile", value=0,
117
- minimum=-0.3, maximum=1.3
118
- )
119
- with gr.Accordion("More Settings", open=False):
120
- src_ratio = gr.Number(
121
- label="Src Ratio", info='''Source ratio''', value=1
122
- )
123
- sample_ratio = gr.Slider(
124
- label="Sample Ratio", info='''Sample ratio''', value=1,
125
- minimum=-0.2, maximum=1.2
126
- )
127
- crop_factor = gr.Slider(
128
- label="Crop Factor", info='''Crop factor''', value=1.7,
129
- minimum=1.5, maximum=2.5
130
- )
131
- output_format = gr.Dropdown(
132
- choices=['webp', 'jpg', 'png'], label="output_format", info='''Format of the output images''', value="webp"
133
- )
134
- output_quality = gr.Number(
135
- label="Output Quality", info='''Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.''', value=95
136
- )
 
 
 
 
 
 
 
137
  submit_btn = gr.Button("Submit")
138
  with gr.Column():
139
  result_image = gr.Image(elem_id="top")
140
  gr.HTML("""
141
- <div style="display: flex; justify-content: center; align-items: center; text-align: center;">
142
  <p style="display: flex;gap: 6px;">
143
  <a href="https://huggingface.co/spaces/fffiloni/expression-editor?duplicate=true">
144
- <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-md.svg" alt="Duplicate this Space">
145
- </a> to skip the queue and enjoy faster inference on the GPU of your choice
146
  </p>
 
147
  </div>
148
  """)
149
 
150
  inputs = [image, rotate_pitch, rotate_yaw, rotate_roll, blink, eyebrow, wink, pupil_x, pupil_y, aaa, eee, woo, smile, src_ratio, sample_ratio, crop_factor, output_format, output_quality]
151
  outputs = [result_image]
152
 
 
 
 
 
 
 
 
153
  submit_btn.click(
154
  fn=predict,
155
  inputs=inputs,
156
  outputs=outputs,
 
157
  )
158
 
159
- rotate_pitch.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
160
- rotate_yaw.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
161
- rotate_roll.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
162
- blink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
163
- eyebrow.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
164
- wink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
165
- pupil_x.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
166
- pupil_y.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
167
- aaa.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
168
- eee.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
169
- woo.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
170
- smile.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
171
 
172
  demo.queue().launch(share=False, show_error=True)
 
6
 
7
  from utils.gradio_helpers import parse_outputs, process_outputs
8
 
9
+ def display_uploaded_image(image_in):
10
+ return image_in
11
+
12
  names = ['image', 'rotate_pitch', 'rotate_yaw', 'rotate_roll', 'blink', 'eyebrow', 'wink', 'pupil_x', 'pupil_y', 'aaa', 'eee', 'woo', 'smile', 'src_ratio', 'sample_ratio', 'crop_factor', 'output_format', 'output_quality']
13
 
14
  def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
 
65
  type="filepath",
66
  height=180
67
  )
68
+ with gr.Tab("HEAD"):
69
+ with gr.Column():
70
+ rotate_pitch = gr.Slider(
71
+ label="Rotate Up-Down",
72
+ value=0,
73
+ minimum=-20, maximum=20
74
+ )
75
+ rotate_yaw = gr.Slider(
76
+ label="Rotate Left-Right turn",
77
+ value=0,
78
+ minimum=-20, maximum=20
79
+ )
80
+ rotate_roll = gr.Slider(
81
+ label="Rotate Left-Right tilt", value=0,
82
+ minimum=-20, maximum=20
83
+ )
84
+ with gr.Tab("EYES"):
85
+ with gr.Column():
86
+ eyebrow = gr.Slider(
87
+ label="Eyebrow", value=0,
88
+ minimum=-10, maximum=15
89
+ )
90
+ with gr.Row():
91
+ blink = gr.Slider(
92
+ label="Blink", value=0,
93
+ minimum=-20, maximum=5
94
+ )
95
+
96
+ wink = gr.Slider(
97
+ label="Wink", value=0,
98
+ minimum=0, maximum=25
99
+ )
100
+ with gr.Row():
101
+ pupil_x = gr.Slider(
102
+ label="Pupil X", value=0,
103
+ minimum=-15, maximum=15
104
+ )
105
+ pupil_y = gr.Slider(
106
+ label="Pupil Y", value=0,
107
+ minimum=-15, maximum=15
108
+ )
109
+ with gr.Tab("MOUTH"):
110
+ with gr.Column():
111
+ with gr.Row():
112
+ aaa = gr.Slider(
113
+ label="Aaa", value=0,
114
+ minimum=-30, maximum=120
115
+ )
116
+ eee = gr.Slider(
117
+ label="Eee", value=0,
118
+ minimum=-20, maximum=15
119
+ )
120
+ woo = gr.Slider(
121
+ label="Woo", value=0,
122
+ minimum=-20, maximum=15
123
+ )
124
+ smile = gr.Slider(
125
+ label="Smile", value=0,
126
+ minimum=-0.3, maximum=1.3
127
+ )
128
+ with gr.Tab("More Settings"):
129
+ with gr.Column():
130
+ src_ratio = gr.Number(
131
+ label="Src Ratio", info='''Source ratio''', value=1
132
+ )
133
+ sample_ratio = gr.Slider(
134
+ label="Sample Ratio", info='''Sample ratio''', value=1,
135
+ minimum=-0.2, maximum=1.2
136
+ )
137
+ crop_factor = gr.Slider(
138
+ label="Crop Factor", info='''Crop factor''', value=1.7,
139
+ minimum=1.5, maximum=2.5
140
+ )
141
+ output_format = gr.Dropdown(
142
+ choices=['webp', 'jpg', 'png'], label="output_format", info='''Format of the output images''', value="webp"
143
+ )
144
+ output_quality = gr.Number(
145
+ label="Output Quality", info='''Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.''', value=95
146
+ )
147
  submit_btn = gr.Button("Submit")
148
  with gr.Column():
149
  result_image = gr.Image(elem_id="top")
150
  gr.HTML("""
151
+ <div style="display: flex; flex-direction: column;justify-content: center; align-items: center; text-align: center;">
152
  <p style="display: flex;gap: 6px;">
153
  <a href="https://huggingface.co/spaces/fffiloni/expression-editor?duplicate=true">
154
+ <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/duplicate-this-space-lg.svg" alt="Duplicate this Space">
155
+ </a>
156
  </p>
157
+ <p>to skip the queue and enjoy faster inference on the GPU of your choice </p>
158
  </div>
159
  """)
160
 
161
  inputs = [image, rotate_pitch, rotate_yaw, rotate_roll, blink, eyebrow, wink, pupil_x, pupil_y, aaa, eee, woo, smile, src_ratio, sample_ratio, crop_factor, output_format, output_quality]
162
  outputs = [result_image]
163
 
164
+ image.upload(
165
+ fn = display_uploaded_image,
166
+ inputs = [image],
167
+ outputs = [result_image],
168
+ queue = False
169
+ )
170
+
171
  submit_btn.click(
172
  fn=predict,
173
  inputs=inputs,
174
  outputs=outputs,
175
+ concurrency_limit=4
176
  )
177
 
178
+ rotate_pitch.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
179
+ rotate_yaw.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
180
+ rotate_roll.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
181
+ blink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
182
+ eyebrow.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
183
+ wink.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
184
+ pupil_x.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
185
+ pupil_y.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
186
+ aaa.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
187
+ eee.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
188
+ woo.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
189
+ smile.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal", concurrency_limit=2)
190
 
191
  demo.queue().launch(share=False, show_error=True)