Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -9,110 +9,99 @@ from utils.gradio_helpers import parse_outputs, process_outputs
|
|
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)):
|
12 |
-
|
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]
|
20 |
-
if value and (os.path.exists(str(value))):
|
21 |
-
value = f"{base_url}/file=" + value
|
22 |
-
if value is not None and value != "":
|
23 |
-
payload["input"][key] = value
|
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)
|
31 |
-
while response.json()["status"] != "succeeded":
|
32 |
-
if response.json()["status"] == "failed":
|
33 |
-
raise gr.Error("The submission failed!")
|
34 |
-
response = requests.get(follow_up_url, headers=headers)
|
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"])
|
42 |
-
processed_outputs = process_outputs(predict_outputs)
|
43 |
-
|
44 |
-
return tuple(processed_outputs) if len(processed_outputs) > 1 else processed_outputs[0]
|
45 |
-
else:
|
46 |
-
if(response.status_code == 409):
|
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 |
def check_password(password):
|
51 |
return password == "pixo"
|
52 |
|
53 |
css = '''
|
54 |
-
#top{position: fixed;}
|
55 |
|
56 |
body {
|
57 |
-
font-family:
|
|
|
|
|
58 |
transition: background-color 0.3s, color 0.3s;
|
59 |
}
|
60 |
|
61 |
-
body.dark-mode {
|
62 |
-
background-color: #1a1a1a;
|
63 |
-
color: #ffffff;
|
64 |
-
}
|
65 |
-
|
66 |
.container {
|
67 |
-
|
68 |
-
|
|
|
|
|
69 |
padding: 20px;
|
70 |
-
|
71 |
-
border-radius: 10px;
|
72 |
-
box-shadow: 0 0 10px rgba(0,0,0,0.1);
|
73 |
}
|
74 |
|
75 |
.gradio-slider input[type="range"] {
|
76 |
-
accent-color: #
|
77 |
}
|
78 |
|
79 |
.gradio-button {
|
80 |
-
background-color: #
|
81 |
color: white;
|
82 |
border: none;
|
83 |
padding: 10px 20px;
|
84 |
border-radius: 5px;
|
85 |
cursor: pointer;
|
86 |
-
transition: background-color 0.3s;
|
|
|
87 |
}
|
88 |
|
89 |
.gradio-button:hover {
|
90 |
-
background-color: #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
}
|
92 |
|
93 |
@media (prefers-color-scheme: dark) {
|
94 |
body {
|
95 |
-
background
|
96 |
-
color: #
|
97 |
}
|
98 |
|
99 |
.container {
|
100 |
-
background-color: rgba(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
}
|
103 |
'''
|
104 |
|
105 |
-
with gr.Blocks(css=css) as demo:
|
106 |
-
gr.Markdown("# Expression Editor")
|
107 |
|
108 |
with gr.Column():
|
109 |
-
password = gr.Textbox(type="password", label="Enter password")
|
110 |
-
login_button = gr.Button("Login")
|
111 |
|
112 |
with gr.Column(visible=False) as main_interface:
|
113 |
-
gr.Markdown("Demo for expression-editor cog image by fofr")
|
114 |
with gr.Row():
|
115 |
-
with gr.Column(elem_classes="container"):
|
116 |
image = gr.Image(
|
117 |
label="Input image",
|
118 |
type="filepath",
|
@@ -190,9 +179,9 @@ with gr.Blocks(css=css) as demo:
|
|
190 |
output_quality = gr.Number(
|
191 |
label="Output Quality", info='''Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.''', value=95
|
192 |
)
|
193 |
-
submit_btn = gr.Button("
|
194 |
-
with gr.Column():
|
195 |
-
result_image = gr.Image(elem_id="top")
|
196 |
gr.HTML("""
|
197 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
198 |
<p style="display: flex;gap: 6px;">
|
|
|
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)):
|
12 |
+
# ... (keep the predict function as is)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
def check_password(password):
|
15 |
return password == "pixo"
|
16 |
|
17 |
css = '''
|
18 |
+
#top{position: fixed; right: 20px; top: 20px; max-width: 300px; z-index: 1000;}
|
19 |
|
20 |
body {
|
21 |
+
font-family: 'Roboto', sans-serif;
|
22 |
+
background: linear-gradient(135deg, #f5d0fe, #d8b4fe);
|
23 |
+
color: #4a0e4e;
|
24 |
transition: background-color 0.3s, color 0.3s;
|
25 |
}
|
26 |
|
|
|
|
|
|
|
|
|
|
|
27 |
.container {
|
28 |
+
background-color: rgba(255, 255, 255, 0.2);
|
29 |
+
backdrop-filter: blur(10px);
|
30 |
+
border-radius: 15px;
|
31 |
+
box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
|
32 |
padding: 20px;
|
33 |
+
margin-bottom: 20px;
|
|
|
|
|
34 |
}
|
35 |
|
36 |
.gradio-slider input[type="range"] {
|
37 |
+
accent-color: #d946ef;
|
38 |
}
|
39 |
|
40 |
.gradio-button {
|
41 |
+
background-color: #a21caf;
|
42 |
color: white;
|
43 |
border: none;
|
44 |
padding: 10px 20px;
|
45 |
border-radius: 5px;
|
46 |
cursor: pointer;
|
47 |
+
transition: background-color 0.3s, transform 0.1s;
|
48 |
+
font-weight: bold;
|
49 |
}
|
50 |
|
51 |
.gradio-button:hover {
|
52 |
+
background-color: #86198f;
|
53 |
+
transform: translateY(-2px);
|
54 |
+
}
|
55 |
+
|
56 |
+
.gradio-slider, .gradio-dropdown, .gradio-checkbox, .gradio-radio, .gradio-textbox, .gradio-number {
|
57 |
+
background-color: rgba(255, 255, 255, 0.1);
|
58 |
+
border: 1px solid rgba(255, 255, 255, 0.2);
|
59 |
+
border-radius: 5px;
|
60 |
+
padding: 10px;
|
61 |
+
margin-bottom: 10px;
|
62 |
+
}
|
63 |
+
|
64 |
+
h1, h2, h3 {
|
65 |
+
color: #701a75;
|
66 |
+
text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
|
67 |
}
|
68 |
|
69 |
@media (prefers-color-scheme: dark) {
|
70 |
body {
|
71 |
+
background: linear-gradient(135deg, #3b0764, #581c87);
|
72 |
+
color: #e9d5ff;
|
73 |
}
|
74 |
|
75 |
.container {
|
76 |
+
background-color: rgba(0, 0, 0, 0.2);
|
77 |
+
}
|
78 |
+
|
79 |
+
h1, h2, h3 {
|
80 |
+
color: #d8b4fe;
|
81 |
+
}
|
82 |
+
|
83 |
+
.gradio-button {
|
84 |
+
background-color: #d946ef;
|
85 |
+
color: #1a1a1a;
|
86 |
+
}
|
87 |
+
|
88 |
+
.gradio-button:hover {
|
89 |
+
background-color: #e879f9;
|
90 |
}
|
91 |
}
|
92 |
'''
|
93 |
|
94 |
+
with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
95 |
+
gr.Markdown("# 🎭 Expression Editor")
|
96 |
|
97 |
with gr.Column():
|
98 |
+
password = gr.Textbox(type="password", label="Enter password", placeholder="Enter 'pixo' to access")
|
99 |
+
login_button = gr.Button("Login", variant="primary")
|
100 |
|
101 |
with gr.Column(visible=False) as main_interface:
|
102 |
+
gr.Markdown("## 🎨 Demo for expression-editor cog image by fofr")
|
103 |
with gr.Row():
|
104 |
+
with gr.Column(scale=2, elem_classes="container"):
|
105 |
image = gr.Image(
|
106 |
label="Input image",
|
107 |
type="filepath",
|
|
|
179 |
output_quality = gr.Number(
|
180 |
label="Output Quality", info='''Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.''', value=95
|
181 |
)
|
182 |
+
submit_btn = gr.Button("Generate", variant="primary")
|
183 |
+
with gr.Column(scale=1):
|
184 |
+
result_image = gr.Image(elem_id="top", label="Generated Image")
|
185 |
gr.HTML("""
|
186 |
<div style="display: flex; justify-content: center; align-items: center; text-align: center;">
|
187 |
<p style="display: flex;gap: 6px;">
|