Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -106,6 +106,8 @@ def select_segment(segment_output, segment_name):
|
|
106 |
|
107 |
def return_image(imageEditor):
|
108 |
return imageEditor['composite']
|
|
|
|
|
109 |
|
110 |
def rembg_client(request: gr.Request):
|
111 |
try:
|
@@ -190,9 +192,26 @@ def upscale_image(image_pil, version="v1.4", rescaling_factor=None):
|
|
190 |
|
191 |
# return inpainting_image(imageEditor['composite'])
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
):
|
197 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
198 |
# hr_image.save(temp_file.name)
|
@@ -205,20 +224,21 @@ def inpainting_run(model_name, use_rasg, use_painta, prompt, imageMask,
|
|
205 |
print("маска", temp_file_path2)
|
206 |
|
207 |
|
208 |
-
client = Client("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU")
|
|
|
209 |
result = client.predict(
|
210 |
input_image_editor={"background":handle_file(temp_file_path),"layers":[handle_file(temp_file_path2)],"composite":None},
|
211 |
prompt=prompt,
|
212 |
negative_prompt=negative_prompt,
|
213 |
-
controlnet_conditioning_scale=
|
214 |
-
guidance_scale=
|
215 |
-
seed=
|
216 |
-
num_inference_steps=
|
217 |
-
true_guidance_scale=
|
218 |
api_name="/process"
|
219 |
)
|
220 |
print(result)
|
221 |
-
return
|
222 |
|
223 |
|
224 |
# client = Client("https://pair-hd-painter.hf.space/--replicas/0l7ng/")
|
@@ -311,12 +331,6 @@ def generate_3d_model2(image_pil, request: gr.Request):
|
|
311 |
|
312 |
### some configs
|
313 |
|
314 |
-
inpainting_models = OrderedDict([
|
315 |
-
("Dreamshaper Inpainting V8", 'ds8_inp'),
|
316 |
-
("Stable-Inpainting 2.0", 'sd2_inp'),
|
317 |
-
("Stable-Inpainting 1.5", 'sd15_inp')
|
318 |
-
])
|
319 |
-
|
320 |
negative_prompt_str = "text, bad anatomy, bad proportions, blurry, cropped, deformed, disfigured, duplicate, error, extra limbs, gross proportions, jpeg artifacts, long neck, low quality, lowres, malformed, morbid, mutated, mutilated, out of frame, ugly, worst quality"
|
321 |
positive_prompt_str = "Full HD, 4K, high quality, high resolution"
|
322 |
|
@@ -338,6 +352,7 @@ with gr.Blocks() as demo:
|
|
338 |
with gr.Row(equal_height=True):
|
339 |
segment_text_input = gr.Textbox(label="Имя сегмента для дальнейшего редактирования")
|
340 |
select_segment_button = gr.Button("Использовать сегмент")
|
|
|
341 |
with gr.Tab("Редактирование"):
|
342 |
with gr.Row(equal_height=True):
|
343 |
with gr.Column(scale=5):
|
@@ -375,85 +390,32 @@ with gr.Blocks() as demo:
|
|
375 |
add_transparent_border_button = gr.Button("Добавить прозрачные края")
|
376 |
use_inpainting_button = gr.Button("Использовать сегмент для Inpainting")
|
377 |
use_button = gr.Button("Использовать сегмент для 3D")
|
|
|
378 |
with gr.Tab("Inpainting"):
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
# with gr.Column(scale=5):
|
383 |
-
# inpainting_text_input = gr.Textbox(label="Текст для Inpainting")
|
384 |
-
# inpainting_button = gr.Button("Inpainting")
|
385 |
-
# use_inpainting_button2 = gr.Button("Вернуться к редактированию")
|
386 |
-
# use_button2 = gr.Button("Использовать сегмент для 3D")
|
387 |
-
|
388 |
-
with gr.Row():
|
389 |
-
session_id = gr.Textbox(value=str(uuid.uuid4()), visible=False)
|
390 |
-
with gr.Column():
|
391 |
-
model_picker = gr.Dropdown(
|
392 |
-
list(inpainting_models.keys()),
|
393 |
-
value=list(inpainting_models.keys())[0],
|
394 |
-
label = "Please select a model!",
|
395 |
-
)
|
396 |
-
with gr.Column():
|
397 |
-
use_painta = gr.Checkbox(value = True, label = "Use PAIntA")
|
398 |
-
use_rasg = gr.Checkbox(value = True, label = "Use RASG")
|
399 |
-
prompt = gr.Textbox(label = "Inpainting Prompt")
|
400 |
-
with gr.Row():
|
401 |
-
with gr.Column():
|
402 |
-
# imageMask = gr.ImageMask(label = "Input Image", brush_color='#ff0000', elem_id="inputmask", type="pil")
|
403 |
-
# imageMask = gr.ImageMask(label = "Input Image", elem_id="inputmask", type="pil")
|
404 |
imageMask = gr.ImageEditor(
|
405 |
-
label='
|
406 |
type='pil',
|
407 |
sources=["upload", "webcam"],
|
408 |
image_mode='RGB',
|
409 |
layers=False,
|
410 |
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
inpaint_btn = gr.Button("Inpaint", scale = 0)
|
415 |
-
|
416 |
with gr.Accordion('Advanced options', open=False):
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
with gr.Row():
|
428 |
-
output_gallery = gr.Gallery(
|
429 |
-
[],
|
430 |
-
columns = 4,
|
431 |
-
preview = True,
|
432 |
-
allow_preview = True,
|
433 |
-
object_fit='scale-down',
|
434 |
-
elem_id='outputgallery'
|
435 |
-
)
|
436 |
-
inpaint_btn.click(
|
437 |
-
fn=inpainting_run,
|
438 |
-
inputs=[
|
439 |
-
model_picker,
|
440 |
-
use_rasg,
|
441 |
-
use_painta,
|
442 |
-
prompt,
|
443 |
-
imageMask,
|
444 |
-
hr_image,
|
445 |
-
seed,
|
446 |
-
eta,
|
447 |
-
negative_prompt,
|
448 |
-
positive_prompt,
|
449 |
-
ddim_steps,
|
450 |
-
guidance_scale,
|
451 |
-
batch_size,
|
452 |
-
session_id
|
453 |
-
],
|
454 |
-
outputs=output_gallery,
|
455 |
-
api_name="inpaint"
|
456 |
-
)
|
457 |
|
458 |
with gr.Tab("Создание 3D"):
|
459 |
with gr.Row(equal_height=True):
|
@@ -476,13 +438,27 @@ with gr.Blocks() as demo:
|
|
476 |
rembg_button.click(rembg, inputs=[segment_input, rembg_model_selector], outputs=segment_input)
|
477 |
remove_background_button.click(remove_black_make_transparent, inputs=segment_input, outputs=segment_input)
|
478 |
add_transparent_border_button.click(add_transparent_border, inputs=[segment_input, add_transparent_border_slider], outputs=segment_input)
|
479 |
-
|
480 |
use_button.click(return_image, inputs=segment_input, outputs=segment_3d_input)
|
481 |
|
482 |
#tab3
|
483 |
# inpainting_button.click(inpainting, inputs=inpainting_input, outputs=inpainting_input)
|
484 |
-
|
485 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
486 |
|
487 |
#3d buttons
|
488 |
hunyuan_button.click(generate_3d_model, inputs=[segment_3d_input, rembg_Hunyuan], outputs=trellis_output)
|
|
|
106 |
|
107 |
def return_image(imageEditor):
|
108 |
return imageEditor['composite']
|
109 |
+
def return_image2(image):
|
110 |
+
return image
|
111 |
|
112 |
def rembg_client(request: gr.Request):
|
113 |
try:
|
|
|
192 |
|
193 |
# return inpainting_image(imageEditor['composite'])
|
194 |
|
195 |
+
|
196 |
+
def inpainting_client(request: gr.Request):
|
197 |
+
try:
|
198 |
+
client = Client("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU", headers={"X-IP-Token": request.headers['x-ip-token']})
|
199 |
+
print("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU Ip token")
|
200 |
+
return client
|
201 |
+
except:
|
202 |
+
print("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU no token")
|
203 |
+
return Client("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU")
|
204 |
+
|
205 |
+
def inpainting_run(input_image_editor,
|
206 |
+
prompt,
|
207 |
+
negative_prompt,
|
208 |
+
controlnet_conditioning_scale,
|
209 |
+
guidance_scale,
|
210 |
+
seed,
|
211 |
+
num_inference_steps,
|
212 |
+
true_guidance_scale,
|
213 |
+
|
214 |
+
request: gr.Request
|
215 |
):
|
216 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
217 |
# hr_image.save(temp_file.name)
|
|
|
224 |
print("маска", temp_file_path2)
|
225 |
|
226 |
|
227 |
+
# client = Client("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU")
|
228 |
+
client = inpainting_client(request)
|
229 |
result = client.predict(
|
230 |
input_image_editor={"background":handle_file(temp_file_path),"layers":[handle_file(temp_file_path2)],"composite":None},
|
231 |
prompt=prompt,
|
232 |
negative_prompt=negative_prompt,
|
233 |
+
controlnet_conditioning_scale=controlnet_conditioning_scale,
|
234 |
+
guidance_scale=guidance_scale,
|
235 |
+
seed=seed,
|
236 |
+
num_inference_steps=num_inference_steps,
|
237 |
+
true_guidance_scale=true_guidance_scale,
|
238 |
api_name="/process"
|
239 |
)
|
240 |
print(result)
|
241 |
+
return result
|
242 |
|
243 |
|
244 |
# client = Client("https://pair-hd-painter.hf.space/--replicas/0l7ng/")
|
|
|
331 |
|
332 |
### some configs
|
333 |
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
negative_prompt_str = "text, bad anatomy, bad proportions, blurry, cropped, deformed, disfigured, duplicate, error, extra limbs, gross proportions, jpeg artifacts, long neck, low quality, lowres, malformed, morbid, mutated, mutilated, out of frame, ugly, worst quality"
|
335 |
positive_prompt_str = "Full HD, 4K, high quality, high resolution"
|
336 |
|
|
|
352 |
with gr.Row(equal_height=True):
|
353 |
segment_text_input = gr.Textbox(label="Имя сегмента для дальнейшего редактирования")
|
354 |
select_segment_button = gr.Button("Использовать сегмент")
|
355 |
+
|
356 |
with gr.Tab("Редактирование"):
|
357 |
with gr.Row(equal_height=True):
|
358 |
with gr.Column(scale=5):
|
|
|
390 |
add_transparent_border_button = gr.Button("Добавить прозрачные края")
|
391 |
use_inpainting_button = gr.Button("Использовать сегмент для Inpainting")
|
392 |
use_button = gr.Button("Использовать сегмент для 3D")
|
393 |
+
|
394 |
with gr.Tab("Inpainting"):
|
395 |
+
with gr.Row(equal_height=True):
|
396 |
+
with gr.Column(scale=5):
|
397 |
+
# inpainting_input = gr.ImageEditor(type="pil", label="Сегмент для Inpainting")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
imageMask = gr.ImageEditor(
|
399 |
+
label='Сегмент для Inpainting',
|
400 |
type='pil',
|
401 |
sources=["upload", "webcam"],
|
402 |
image_mode='RGB',
|
403 |
layers=False,
|
404 |
brush=gr.Brush(colors=["#FFFFFF"], color_mode="fixed"))
|
405 |
+
|
406 |
+
prompt = gr.Textbox(lines=2, label="Введите промпт для Inpainting", placeholder="Enter prompt here...")
|
407 |
+
inpainting_button = gr.Button("Inpainting")
|
|
|
|
|
408 |
with gr.Accordion('Advanced options', open=False):
|
409 |
+
negative_prompt = gr.Textbox(lines=2, value=negative_prompt_str, label="Negative prompt", placeholder="Enter negative_prompt here...")
|
410 |
+
controlnet_conditioning_scale = gr.Slider(minimum=0, step=0.01, maximum=1, value=0.9, label="controlnet_conditioning_scale")
|
411 |
+
guidance_scale = gr.Slider(minimum=1, step=0.5, maximum=10, value=3.5, label="Image to generate")
|
412 |
+
seed = gr.Slider(minimum=0, step=1, maximum=10000000, value=124, label="Seed Value")
|
413 |
+
num_inference_steps = gr.Slider(minimum=1, step=1, maximum=30, value=24, label="num_inference_steps")
|
414 |
+
true_guidance_scale = gr.Slider(minimum=1, step=1, maximum=10, value=3.5, label="true_guidance_scale")
|
415 |
+
with gr.Column(scale=5):
|
416 |
+
after_inpainting = gr.Image(type="pil", label="Изображение после Inpainting")
|
417 |
+
use_inpainting_button2 = gr.Button("Вернуться к редактированию")
|
418 |
+
use_button2 = gr.Button("Использовать сегмент для 3D")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
419 |
|
420 |
with gr.Tab("Создание 3D"):
|
421 |
with gr.Row(equal_height=True):
|
|
|
438 |
rembg_button.click(rembg, inputs=[segment_input, rembg_model_selector], outputs=segment_input)
|
439 |
remove_background_button.click(remove_black_make_transparent, inputs=segment_input, outputs=segment_input)
|
440 |
add_transparent_border_button.click(add_transparent_border, inputs=[segment_input, add_transparent_border_slider], outputs=segment_input)
|
441 |
+
use_inpainting_button.click(return_image, inputs=segment_input, outputs=imageMask)
|
442 |
use_button.click(return_image, inputs=segment_input, outputs=segment_3d_input)
|
443 |
|
444 |
#tab3
|
445 |
# inpainting_button.click(inpainting, inputs=inpainting_input, outputs=inpainting_input)
|
446 |
+
inpainting_button.click(
|
447 |
+
fn=inpainting_run,
|
448 |
+
inputs=[
|
449 |
+
imageMask,
|
450 |
+
prompt,
|
451 |
+
negative_prompt,
|
452 |
+
controlnet_conditioning_scale,
|
453 |
+
guidance_scale,
|
454 |
+
seed,
|
455 |
+
num_inference_steps,
|
456 |
+
true_guidance_scale
|
457 |
+
],
|
458 |
+
outputs=after_inpainting
|
459 |
+
)
|
460 |
+
use_inpainting_button2.click(return_image2, inputs=after_inpainting, outputs=segment_input)
|
461 |
+
use_button2.click(return_image2, inputs=after_inpainting, outputs=segment_3d_input)
|
462 |
|
463 |
#3d buttons
|
464 |
hunyuan_button.click(generate_3d_model, inputs=[segment_3d_input, rembg_Hunyuan], outputs=trellis_output)
|