Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -62,7 +62,7 @@ def upload_template(image_path):
|
|
62 |
def easyphoto_train(instance_images):
|
63 |
images = []
|
64 |
if instance_images is None or len(instance_images)==0:
|
65 |
-
output = 'Status: no image updated!
|
66 |
return output, [], []
|
67 |
for number, image in enumerate(instance_images):
|
68 |
image_path = image['name']
|
@@ -75,13 +75,13 @@ def easyphoto_train(instance_images):
|
|
75 |
model_id = response.data['model_id']
|
76 |
job_id = response.data['job_id']
|
77 |
if message == 'success':
|
78 |
-
state = 'training job submitted.
|
79 |
output = 'Status: ' + state
|
80 |
print("job id: " + str(job_id))
|
81 |
print("model id: " + str(model_id))
|
82 |
return output, job_id, model_id
|
83 |
else:
|
84 |
-
output = 'Status: submitting training job failed!
|
85 |
return output, [], []
|
86 |
|
87 |
|
@@ -89,7 +89,7 @@ def easyphoto_check(job_id):
|
|
89 |
client = ApiClient(host, appId, token)
|
90 |
api = AiServiceJobApi(client)
|
91 |
if job_id is None:
|
92 |
-
output = 'Status: checking training status failed! No job id.
|
93 |
else:
|
94 |
try:
|
95 |
job_id = int(str(job_id).strip())
|
@@ -97,14 +97,14 @@ def easyphoto_check(job_id):
|
|
97 |
message = response.data['job']['message']
|
98 |
output = 'Status: ' + message
|
99 |
except:
|
100 |
-
output = 'Status: checking training status failed!
|
101 |
return output
|
102 |
|
103 |
|
104 |
def easyphoto_infer(model_id, selected_template_images, additional_prompt, seed, before_face_fusion_ratio, after_face_fusion_ratio, first_diffusion_steps, first_denoising_strength, second_diffusion_steps, second_denoising_strength, crop_face_preprocess, apply_face_fusion_before, apply_face_fusion_after, color_shift_middle, color_shift_last, background_restore):
|
105 |
image_urls = []
|
106 |
if len(selected_template_images) == 0:
|
107 |
-
output_info = 'Status: no templete selected!
|
108 |
return output_info, []
|
109 |
selected_template_images = eval(selected_template_images)
|
110 |
for image in selected_template_images:
|
@@ -117,7 +117,7 @@ def easyphoto_infer(model_id, selected_template_images, additional_prompt, seed,
|
|
117 |
output_info = None
|
118 |
|
119 |
if model_id is None:
|
120 |
-
output_info = 'Status: no model id provided!
|
121 |
return output_info, []
|
122 |
|
123 |
model_id = str(model_id).strip()
|
@@ -152,48 +152,43 @@ def easyphoto_infer(model_id, selected_template_images, additional_prompt, seed,
|
|
152 |
image = data['image']
|
153 |
image = decode_image_from_base64jpeg(image)
|
154 |
outputs.append(image)
|
155 |
-
output_info = 'Status: generating image succesfully!
|
156 |
else:
|
157 |
-
output_info = 'Status: generating image failed!
|
158 |
return output_info, []
|
159 |
return output_info, outputs
|
160 |
|
161 |
|
162 |
with gr.Blocks() as easyphoto_demo:
|
163 |
model_id = gr.Textbox(visible=False)
|
164 |
-
with gr.TabItem('Training
|
165 |
with gr.Blocks():
|
166 |
with gr.Row():
|
167 |
with gr.Column():
|
168 |
instance_images = gr.Gallery().style(columns=[4], rows=[2], object_fit="contain", height="auto")
|
169 |
with gr.Row():
|
170 |
upload_button = gr.UploadButton(
|
171 |
-
"Upload Photos
|
172 |
)
|
173 |
-
clear_button = gr.Button("Clear Photos
|
174 |
clear_button.click(fn=lambda: [], inputs=None, outputs=instance_images)
|
175 |
upload_button.upload(upload_file, inputs=[upload_button, instance_images], outputs=instance_images, queue=False)
|
176 |
gr.Markdown(
|
177 |
'''
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
3.当模型训练完成后,任务状态会显示success,切换到推理模式,并根据模板生成照片。
|
185 |
-
|
186 |
-
4.如果在上传时遇到卡顿,请修改上传图片的���小,尽量限制在1.5MB以内。
|
187 |
-
|
188 |
-
5.在训练或推理过程中,请不要刷新或关闭窗口。
|
189 |
'''
|
190 |
)
|
191 |
|
192 |
job_id = gr.Textbox(visible=False)
|
193 |
with gr.Row():
|
194 |
-
run_button = gr.Button('Submit My Training Job
|
195 |
-
check_button = gr.Button('Check My Training Job Status
|
196 |
-
output_message = gr.Textbox(value="", label="Status
|
197 |
|
198 |
run_button.click(fn=easyphoto_train,
|
199 |
inputs=[instance_images],
|
@@ -204,7 +199,7 @@ with gr.Blocks() as easyphoto_demo:
|
|
204 |
outputs=[output_message])
|
205 |
|
206 |
|
207 |
-
with gr.TabItem('Inference
|
208 |
templates = glob.glob(r'./*.jpg')
|
209 |
preset_template = list(templates)
|
210 |
|
@@ -220,7 +215,7 @@ with gr.Blocks() as easyphoto_demo:
|
|
220 |
selected_template_images = gr.Text(show_label=False, visible=False, placeholder="Selected")
|
221 |
gallery.select(select_function, None, selected_template_images)
|
222 |
|
223 |
-
with gr.Accordion("Advanced Options
|
224 |
additional_prompt = gr.Textbox(
|
225 |
label="Additional Prompt",
|
226 |
lines=3,
|
@@ -295,30 +290,18 @@ with gr.Blocks() as easyphoto_demo:
|
|
295 |
3. **Crop Face Preprocess** represents whether to crop the image before generation, which can adapt to images with smaller faces.
|
296 |
4. **Apply Face Fusion Before** represents whether to perform the first facial fusion.
|
297 |
5. **Apply Face Fusion After** represents whether to perform the second facial fusion.
|
298 |
-
|
299 |
-
参数:
|
300 |
-
|
301 |
-
1.**Face Fusion Ratio Before**表示第一次面部融合的比例,更高且更接近训练对象。
|
302 |
-
|
303 |
-
2.**Face Fusion Ratio After**表示第二次面部融合的比例,更高且更接近训练对象。
|
304 |
-
|
305 |
-
3.**Crop Face Preprocess**表示是否在生成之前裁剪图像,以适应面部较小的图像。
|
306 |
-
|
307 |
-
4.**Apply Face Fusion Before**表示是否执行第一次面部融合。
|
308 |
-
|
309 |
-
5.**Apply Face Fusion After**表示是否执行第二次面部融合。
|
310 |
'''
|
311 |
)
|
312 |
|
313 |
with gr.Column():
|
314 |
-
gr.Markdown('Generated Results
|
315 |
output_images = gr.Gallery(
|
316 |
label='Output',
|
317 |
show_label=False
|
318 |
).style(columns=[4], rows=[2], object_fit="contain", height="auto")
|
319 |
-
display_button = gr.Button('Start Generation
|
320 |
infer_progress = gr.Textbox(
|
321 |
-
label="Generation Progress
|
322 |
value="",
|
323 |
interactive=False
|
324 |
)
|
@@ -331,13 +314,13 @@ with gr.Blocks() as easyphoto_demo:
|
|
331 |
|
332 |
gr.Markdown(
|
333 |
"""
|
334 |
-
|
335 |
|
336 |
-
EasyPhoto GitHub
|
337 |
|
338 |
-
|
339 |
|
340 |
-
|
341 |
""")
|
342 |
|
343 |
easyphoto_demo.launch(share=False).queue()
|
|
|
62 |
def easyphoto_train(instance_images):
|
63 |
images = []
|
64 |
if instance_images is None or len(instance_images)==0:
|
65 |
+
output = 'Status: no image updated!'
|
66 |
return output, [], []
|
67 |
for number, image in enumerate(instance_images):
|
68 |
image_path = image['name']
|
|
|
75 |
model_id = response.data['model_id']
|
76 |
job_id = response.data['job_id']
|
77 |
if message == 'success':
|
78 |
+
state = 'training job submitted.'
|
79 |
output = 'Status: ' + state
|
80 |
print("job id: " + str(job_id))
|
81 |
print("model id: " + str(model_id))
|
82 |
return output, job_id, model_id
|
83 |
else:
|
84 |
+
output = 'Status: submitting training job failed!'
|
85 |
return output, [], []
|
86 |
|
87 |
|
|
|
89 |
client = ApiClient(host, appId, token)
|
90 |
api = AiServiceJobApi(client)
|
91 |
if job_id is None:
|
92 |
+
output = 'Status: checking training status failed! No job id.'
|
93 |
else:
|
94 |
try:
|
95 |
job_id = int(str(job_id).strip())
|
|
|
97 |
message = response.data['job']['message']
|
98 |
output = 'Status: ' + message
|
99 |
except:
|
100 |
+
output = 'Status: checking training status failed!'
|
101 |
return output
|
102 |
|
103 |
|
104 |
def easyphoto_infer(model_id, selected_template_images, additional_prompt, seed, before_face_fusion_ratio, after_face_fusion_ratio, first_diffusion_steps, first_denoising_strength, second_diffusion_steps, second_denoising_strength, crop_face_preprocess, apply_face_fusion_before, apply_face_fusion_after, color_shift_middle, color_shift_last, background_restore):
|
105 |
image_urls = []
|
106 |
if len(selected_template_images) == 0:
|
107 |
+
output_info = 'Status: no templete selected!'
|
108 |
return output_info, []
|
109 |
selected_template_images = eval(selected_template_images)
|
110 |
for image in selected_template_images:
|
|
|
117 |
output_info = None
|
118 |
|
119 |
if model_id is None:
|
120 |
+
output_info = 'Status: no model id provided!'
|
121 |
return output_info, []
|
122 |
|
123 |
model_id = str(model_id).strip()
|
|
|
152 |
image = data['image']
|
153 |
image = decode_image_from_base64jpeg(image)
|
154 |
outputs.append(image)
|
155 |
+
output_info = 'Status: generating image succesfully!'
|
156 |
else:
|
157 |
+
output_info = 'Status: generating image failed!'
|
158 |
return output_info, []
|
159 |
return output_info, outputs
|
160 |
|
161 |
|
162 |
with gr.Blocks() as easyphoto_demo:
|
163 |
model_id = gr.Textbox(visible=False)
|
164 |
+
with gr.TabItem('Training'):
|
165 |
with gr.Blocks():
|
166 |
with gr.Row():
|
167 |
with gr.Column():
|
168 |
instance_images = gr.Gallery().style(columns=[4], rows=[2], object_fit="contain", height="auto")
|
169 |
with gr.Row():
|
170 |
upload_button = gr.UploadButton(
|
171 |
+
"Upload Photos", file_types=["image"], file_count="multiple"
|
172 |
)
|
173 |
+
clear_button = gr.Button("Clear Photos")
|
174 |
clear_button.click(fn=lambda: [], inputs=None, outputs=instance_images)
|
175 |
upload_button.upload(upload_file, inputs=[upload_button, instance_images], outputs=instance_images, queue=False)
|
176 |
gr.Markdown(
|
177 |
'''
|
178 |
+
Training steps:
|
179 |
+
1. Please upload 5-20 half-body photos or head and shoulder photos, ensuring that the facial proportions are not too small.
|
180 |
+
2. Click the training button below to submit the training task. It will take approximately 15 minutes, and you can check the status of your training task. Please refrain from clicking the submit training task button multiple times!
|
181 |
+
3. Once the model training is completed, the task status will display success. Switch to inference mode and generate photos based on the template.
|
182 |
+
4. If you experience lag during uploading, please resize the uploaded images to a size below 1.5MB if possible.
|
183 |
+
5. During the training or inference process, please do not refresh or close the window.
|
|
|
|
|
|
|
|
|
|
|
184 |
'''
|
185 |
)
|
186 |
|
187 |
job_id = gr.Textbox(visible=False)
|
188 |
with gr.Row():
|
189 |
+
run_button = gr.Button('Submit My Training Job')
|
190 |
+
check_button = gr.Button('Check My Training Job Status')
|
191 |
+
output_message = gr.Textbox(value="", label="Status", interactive=False)
|
192 |
|
193 |
run_button.click(fn=easyphoto_train,
|
194 |
inputs=[instance_images],
|
|
|
199 |
outputs=[output_message])
|
200 |
|
201 |
|
202 |
+
with gr.TabItem('Inference'):
|
203 |
templates = glob.glob(r'./*.jpg')
|
204 |
preset_template = list(templates)
|
205 |
|
|
|
215 |
selected_template_images = gr.Text(show_label=False, visible=False, placeholder="Selected")
|
216 |
gallery.select(select_function, None, selected_template_images)
|
217 |
|
218 |
+
with gr.Accordion("Advanced Options", open=False):
|
219 |
additional_prompt = gr.Textbox(
|
220 |
label="Additional Prompt",
|
221 |
lines=3,
|
|
|
290 |
3. **Crop Face Preprocess** represents whether to crop the image before generation, which can adapt to images with smaller faces.
|
291 |
4. **Apply Face Fusion Before** represents whether to perform the first facial fusion.
|
292 |
5. **Apply Face Fusion After** represents whether to perform the second facial fusion.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
'''
|
294 |
)
|
295 |
|
296 |
with gr.Column():
|
297 |
+
gr.Markdown('Generated Results')
|
298 |
output_images = gr.Gallery(
|
299 |
label='Output',
|
300 |
show_label=False
|
301 |
).style(columns=[4], rows=[2], object_fit="contain", height="auto")
|
302 |
+
display_button = gr.Button('Start Generation')
|
303 |
infer_progress = gr.Textbox(
|
304 |
+
label="Generation Progress",
|
305 |
value="",
|
306 |
interactive=False
|
307 |
)
|
|
|
314 |
|
315 |
gr.Markdown(
|
316 |
"""
|
317 |
+
Useful Links
|
318 |
|
319 |
+
EasyPhoto GitHub: https://github.com/aigc-apps/sd-webui-EasyPhoto
|
320 |
|
321 |
+
Alibaba Cloud Freetier: https://help.aliyun.com/document_detail/2567864.html
|
322 |
|
323 |
+
PAI-DSW Gallery: https://gallery.pai-ml.com/#/preview/deepLearning/cv/stable_diffusion_easyphoto
|
324 |
""")
|
325 |
|
326 |
easyphoto_demo.launch(share=False).queue()
|