tsi-org commited on
Commit
c606315
·
verified ·
1 Parent(s): 6d90ae1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -19
app.py CHANGED
@@ -13,7 +13,6 @@ def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
13
 
14
  payload = {"input": {}}
15
 
16
-
17
  base_url = "http://0.0.0.0:7860"
18
  for i, key in enumerate(names):
19
  value = args[i]
@@ -24,7 +23,6 @@ def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
24
 
25
  response = requests.post("http://0.0.0.0:5000/predictions", headers=headers, json=payload)
26
 
27
-
28
  if response.status_code == 201:
29
  follow_up_url = response.json()["urls"]["get"]
30
  response = requests.get(follow_up_url, headers=headers)
@@ -35,7 +33,6 @@ def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
35
  time.sleep(1)
36
  if response.status_code == 200:
37
  json_response = response.json()
38
- #If the output component is JSON return the entire output response
39
  if(outputs[0].get_config()["name"] == "json"):
40
  return json_response["output"]
41
  predict_outputs = parse_outputs(json_response["output"])
@@ -47,16 +44,58 @@ def predict(request: gr.Request, *args, progress=gr.Progress(track_tqdm=True)):
47
  raise gr.Error(f"Sorry, the Cog image is still processing. Try again in a bit.")
48
  raise gr.Error(f"The submission failed! Error: {response.status_code}")
49
 
 
 
50
 
51
  css = '''
52
- #top{position: fixed;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  '''
54
- with gr.Blocks() as demo:
 
 
 
55
  with gr.Column():
56
- gr.Markdown("# Expression Editor")
 
 
 
57
  gr.Markdown("Demo for expression-editor cog image by fofr")
58
  with gr.Row():
59
- with gr.Column():
60
  image = gr.Image(
61
  label="Input image",
62
  type="filepath",
@@ -150,23 +189,25 @@ with gr.Blocks() as demo:
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.launch(share=False, show_error=True)
 
13
 
14
  payload = {"input": {}}
15
 
 
16
  base_url = "http://0.0.0.0:7860"
17
  for i, key in enumerate(names):
18
  value = args[i]
 
23
 
24
  response = requests.post("http://0.0.0.0:5000/predictions", headers=headers, json=payload)
25
 
 
26
  if response.status_code == 201:
27
  follow_up_url = response.json()["urls"]["get"]
28
  response = requests.get(follow_up_url, headers=headers)
 
33
  time.sleep(1)
34
  if response.status_code == 200:
35
  json_response = response.json()
 
36
  if(outputs[0].get_config()["name"] == "json"):
37
  return json_response["output"]
38
  predict_outputs = parse_outputs(json_response["output"])
 
44
  raise gr.Error(f"Sorry, the Cog image is still processing. Try again in a bit.")
45
  raise gr.Error(f"The submission failed! Error: {response.status_code}")
46
 
47
+ def check_password(password):
48
+ return password == "pixo"
49
 
50
  css = '''
51
+ body {
52
+ font-family: Arial, sans-serif;
53
+ background-color: #f0f0f0;
54
+ }
55
+ .container {
56
+ max-width: 1200px;
57
+ margin: 0 auto;
58
+ padding: 20px;
59
+ background-color: white;
60
+ border-radius: 10px;
61
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
62
+ }
63
+ .gradio-slider input[type="range"] {
64
+ accent-color: #3498db;
65
+ }
66
+ .gradio-button {
67
+ background-color: #3498db;
68
+ color: white;
69
+ border: none;
70
+ padding: 10px 20px;
71
+ border-radius: 5px;
72
+ cursor: pointer;
73
+ transition: background-color 0.3s;
74
+ }
75
+ .gradio-button:hover {
76
+ background-color: #2980b9;
77
+ }
78
+ #top {
79
+ position: fixed;
80
+ top: 20px;
81
+ right: 20px;
82
+ max-width: 300px;
83
+ border-radius: 10px;
84
+ box-shadow: 0 0 10px rgba(0,0,0,0.1);
85
+ }
86
  '''
87
+
88
+ with gr.Blocks(css=css) as demo:
89
+ gr.Markdown("# Expression Editor")
90
+
91
  with gr.Column():
92
+ password = gr.Textbox(type="password", label="Enter password")
93
+ login_button = gr.Button("Login")
94
+
95
+ with gr.Column(visible=False) as main_interface:
96
  gr.Markdown("Demo for expression-editor cog image by fofr")
97
  with gr.Row():
98
+ with gr.Column(elem_classes="container"):
99
  image = gr.Image(
100
  label="Input image",
101
  type="filepath",
 
189
  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]
190
  outputs = [result_image]
191
 
192
+ def login(password):
193
+ if check_password(password):
194
+ return gr.update(visible=True), gr.update(visible=False)
195
+ else:
196
+ return gr.update(visible=False), gr.update(visible=True, value="")
197
+
198
+ login_button.click(
199
+ fn=login,
200
+ inputs=[password],
201
+ outputs=[main_interface, password]
202
+ )
203
+
204
  submit_btn.click(
205
  fn=predict,
206
  inputs=inputs,
207
  outputs=outputs,
208
  )
209
 
210
+ for slider in [rotate_pitch, rotate_yaw, rotate_roll, blink, eyebrow, wink, pupil_x, pupil_y, aaa, eee, woo, smile]:
211
+ slider.release(fn=predict, inputs=inputs, outputs=outputs, show_progress="minimal")
 
 
 
 
 
 
 
 
 
 
212
 
213
  demo.launch(share=False, show_error=True)