Jinl commited on
Commit
65b07e7
1 Parent(s): 3300cca

restore gradio

Browse files
Files changed (2) hide show
  1. app.py +24 -13
  2. gr4_test.py +15 -0
app.py CHANGED
@@ -1,3 +1,11 @@
 
 
 
 
 
 
 
 
1
  import os
2
  import json
3
  import re
@@ -31,6 +39,7 @@ from torchvision.utils import save_image
31
  from diffusers.models.attention_processor import AttnProcessor2_0
32
 
33
 
 
34
 
35
 
36
  css = """
@@ -281,7 +290,7 @@ class GlobalText:
281
 
282
  global_text = GlobalText()
283
 
284
-
285
  def load_mask_images(source,style,source_mask,style_mask,device,width,height,out_dir=None):
286
  # invert the image into noise map
287
  if isinstance(source['image'], np.ndarray):
@@ -323,6 +332,7 @@ def load_mask_images(source,style,source_mask,style_mask,device,width,height,out
323
  return source_image,style_image,source_mask,style_mask
324
 
325
 
 
326
  def ui():
327
  with gr.Blocks(css=css) as demo:
328
  gr.Markdown(
@@ -393,14 +403,14 @@ def ui():
393
  with gr.Tab("Configs"):
394
 
395
  with gr.Row():
396
- source_image = gr.Image(label="Source Image", elem_id="img2maskimg", sources="upload", interactive=True, type="pil",image_mode="RGB", height=512)
397
- style_image = gr.Image(label="Style Image", elem_id="img2maskimg", sources="upload", interactive=True, type="pil", image_mode="RGB", height=512)
398
  with gr.Row():
399
  prompt_textbox = gr.Textbox(label="Prompt", value='head', lines=1)
400
  negative_prompt_textbox = gr.Textbox(label="Negative prompt", lines=1)
401
  # output_dir = gr.Textbox(label="output_dir", value='./results/')
402
 
403
- with gr.Row(equal_height=False):
404
  with gr.Column():
405
  width_slider = gr.Slider(label="Width", value=512, minimum=256, maximum=1024, step=64)
406
  height_slider = gr.Slider(label="Height", value=512, minimum=256, maximum=1024, step=64)
@@ -487,22 +497,23 @@ def ui():
487
  sam_style_btn = gr.Button(value="SAM Style")
488
  send_style_btn = gr.Button(value="Send Style")
489
  with gr.Row():
490
- source_image_sam = gr.Image(label="Source Image SAM", elem_id="SourceimgSAM", sources="upload", interactive=True, type="pil", image_mode="RGB", height=512)
491
- style_image_sam = gr.Image(label="Style Image SAM", elem_id="StyleimgSAM", sources="upload", interactive=True, type="pil", image_mode="RGB", height=512)
492
 
493
  with gr.Row():
494
  source_image_with_points = gr.Image(label="source Image with points", elem_id="style_image_with_points", type="pil", image_mode="RGB", height=256)
495
- source_mask = gr.Image(label="Source Mask", elem_id="img2maskimg", sources="upload", interactive=True, type="numpy", image_mode="RGB", height=256)
496
 
497
  style_image_with_points = gr.Image(label="Style Image with points", elem_id="style_image_with_points", type="pil", image_mode="RGB", height=256)
498
- style_mask = gr.Image(label="Style Mask", elem_id="img2maskimg", sources="upload", interactive=True, type="numpy", image_mode="RGB", height=256)
 
499
  gr.Examples(
500
- [[os.path.join(os.path.dirname(__file__), "images/content/1.jpg"),
501
- os.path.join(os.path.dirname(__file__), "images/style/1.jpg")]],
502
- #/home/jin.liu/liujin/mycode/PortraitDiffusion/images/style/1.jpg
503
- [source_image, style_image]
 
504
  )
505
-
506
  inputs = [
507
  source_image, style_image, source_mask, style_mask,
508
  start_step, start_layer, Style_attn_step,
 
1
+ import subprocess
2
+
3
+ # 执行shell命令
4
+ command = "pip install gradio==3.47"
5
+ result = subprocess.run(command, shell=True, capture_output=True, text=True)
6
+
7
+
8
+
9
  import os
10
  import json
11
  import re
 
39
  from diffusers.models.attention_processor import AttnProcessor2_0
40
 
41
 
42
+ # 在 python 中使用 pip 安装 3.41 版本的 gradio
43
 
44
 
45
  css = """
 
290
 
291
  global_text = GlobalText()
292
 
293
+ gr.ImageMask()
294
  def load_mask_images(source,style,source_mask,style_mask,device,width,height,out_dir=None):
295
  # invert the image into noise map
296
  if isinstance(source['image'], np.ndarray):
 
332
  return source_image,style_image,source_mask,style_mask
333
 
334
 
335
+
336
  def ui():
337
  with gr.Blocks(css=css) as demo:
338
  gr.Markdown(
 
403
  with gr.Tab("Configs"):
404
 
405
  with gr.Row():
406
+ source_image = gr.Image(label="Source Image", elem_id="img2maskimg", source="upload", interactive=True, type="pil", tool="sketch", image_mode="RGB", height=512)
407
+ style_image = gr.Image(label="Style Image", elem_id="img2maskimg", source="upload", interactive=True, type="pil", tool="sketch", image_mode="RGB", height=512)
408
  with gr.Row():
409
  prompt_textbox = gr.Textbox(label="Prompt", value='head', lines=1)
410
  negative_prompt_textbox = gr.Textbox(label="Negative prompt", lines=1)
411
  # output_dir = gr.Textbox(label="output_dir", value='./results/')
412
 
413
+ with gr.Row().style(equal_height=False):
414
  with gr.Column():
415
  width_slider = gr.Slider(label="Width", value=512, minimum=256, maximum=1024, step=64)
416
  height_slider = gr.Slider(label="Height", value=512, minimum=256, maximum=1024, step=64)
 
497
  sam_style_btn = gr.Button(value="SAM Style")
498
  send_style_btn = gr.Button(value="Send Style")
499
  with gr.Row():
500
+ source_image_sam = gr.Image(label="Source Image SAM", elem_id="SourceimgSAM", source="upload", interactive=True, type="pil", image_mode="RGB", height=512)
501
+ style_image_sam = gr.Image(label="Style Image SAM", elem_id="StyleimgSAM", source="upload", interactive=True, type="pil", image_mode="RGB", height=512)
502
 
503
  with gr.Row():
504
  source_image_with_points = gr.Image(label="source Image with points", elem_id="style_image_with_points", type="pil", image_mode="RGB", height=256)
505
+ source_mask = gr.Image(label="Source Mask", elem_id="img2maskimg", source="upload", interactive=True, type="numpy", image_mode="RGB", height=256)
506
 
507
  style_image_with_points = gr.Image(label="Style Image with points", elem_id="style_image_with_points", type="pil", image_mode="RGB", height=256)
508
+ style_mask = gr.Image(label="Style Mask", elem_id="img2maskimg", source="upload", interactive=True, type="numpy", image_mode="RGB", height=256)
509
+
510
  gr.Examples(
511
+ [[os.path.join(os.path.dirname(__file__), "gradio_app/images/content/1.jpg"),
512
+ os.path.join(os.path.dirname(__file__), "gradio_app/images/style/1.jpg")],
513
+
514
+ ],
515
+ [source_image, style_image]
516
  )
 
517
  inputs = [
518
  source_image, style_image, source_mask, style_mask,
519
  start_step, start_layer, Style_attn_step,
gr4_test.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ cnt = 0
4
+
5
+ def test():
6
+ cnt += 1
7
+ return f'triggered!{cnt}'
8
+
9
+
10
+ with gr.Blocks() as demo:
11
+ sketch_pad = gr.ImageEditor(type="pil")
12
+ output_text = gr.Textbox(label='Output Text')
13
+ sketch_pad.change(test, outputs=[output_text])
14
+
15
+ demo.launch()