JingyeChen commited on
Commit
2c24e74
1 Parent(s): 9e15e2e
Files changed (1) hide show
  1. app.py +33 -30
app.py CHANGED
@@ -83,28 +83,27 @@ pipe.load_lora_weights(lcm_lora_id)
83
  pipe.to(device="cuda")
84
 
85
 
86
- #### for interactive
87
- stack = []
88
- state = 0
89
  font = ImageFont.truetype("./Arial.ttf", 32)
90
 
91
- def skip_fun(i, t):
92
- global state
93
  state = 0
 
94
 
95
 
96
- def exe_undo(i, t):
97
- global stack
98
- global state
99
  state = 0
100
  stack = []
101
  image = Image.open(f'./gray256.jpg')
102
  print('stack', stack)
103
- return image
104
 
105
 
106
- def exe_redo(i, t):
107
- global state
108
  state = 0
109
 
110
  if len(stack) > 0:
@@ -134,10 +133,10 @@ def exe_redo(i, t):
134
  draw.rectangle((x0,y0,x1,y1), outline=(255, 0, 0) )
135
 
136
  print('stack', stack)
137
- return image
138
 
139
- def get_pixels(i, t, evt: gr.SelectData):
140
- global state
141
 
142
  text_position = evt.index
143
 
@@ -183,7 +182,7 @@ def get_pixels(i, t, evt: gr.SelectData):
183
 
184
  print('stack', stack)
185
 
186
- return image
187
 
188
 
189
  font_layout = ImageFont.truetype('./Arial.ttf', 16)
@@ -407,6 +406,10 @@ def text_to_image(prompt,keywords,positive_prompt,radio,slider_step,slider_guida
407
 
408
  with gr.Blocks() as demo:
409
 
 
 
 
 
410
  gr.HTML(
411
  """
412
  <div style="text-align: center; max-width: 1600px; margin: 20px auto;">
@@ -447,21 +450,21 @@ with gr.Blocks() as demo:
447
  keywords = gr.Textbox(label="(Optional) Keywords. Should be seperated by / (e.g., keyword1/keyword2/...)", placeholder="keyword1/keyword2")
448
  positive_prompt = gr.Textbox(label="(Optional) Positive prompt", value=", digital art, very detailed, fantasy, high definition, cinematic light, dnd, trending on artstation")
449
 
450
- # # many encounter concurrent problem
451
- # with gr.Accordion("(Optional) Template - Click to paint", open=False):
452
- # with gr.Row():
453
- # with gr.Column(scale=1):
454
- # i = gr.Image(label="Canvas", type='filepath', value=f'./gray256.jpg', height=256, width=256)
455
- # with gr.Column(scale=1):
456
- # t = gr.Textbox(label="Keyword", value='input_keyword')
457
- # redo = gr.Button(value='Redo - Cancel the last keyword')
458
- # undo = gr.Button(value='Undo - Clear the canvas')
459
- # skip_button = gr.Button(value='Skip - Operate the next keyword')
460
-
461
- # i.select(get_pixels,[i,t],[i])
462
- # redo.click(exe_redo, [i,t],[i])
463
- # undo.click(exe_undo, [i,t],[i])
464
- # skip_button.click(skip_fun, [i,t])
465
 
466
  radio = gr.Radio(["TextDiffuser-2", "TextDiffuser-2-LCM"], label="Choice of models", value="TextDiffuser-2")
467
  slider_natural = gr.Checkbox(label="Natural image generation", value=False, info="The text position and content info will not be incorporated.")
 
83
  pipe.to(device="cuda")
84
 
85
 
86
+
 
 
87
  font = ImageFont.truetype("./Arial.ttf", 32)
88
 
89
+ def skip_fun(i, t, stack, state):
90
+ # global state
91
  state = 0
92
+ return i, stack, state
93
 
94
 
95
+ def exe_undo(i, t, stack, state):
96
+ # global stack
97
+ # global state
98
  state = 0
99
  stack = []
100
  image = Image.open(f'./gray256.jpg')
101
  print('stack', stack)
102
+ return image, stack, state
103
 
104
 
105
+ def exe_redo(i, t, stack, state):
106
+ # global state
107
  state = 0
108
 
109
  if len(stack) > 0:
 
133
  draw.rectangle((x0,y0,x1,y1), outline=(255, 0, 0) )
134
 
135
  print('stack', stack)
136
+ return image, stack, state
137
 
138
+ def get_pixels(i, t, stack, state, evt: gr.SelectData):
139
+ # global state
140
 
141
  text_position = evt.index
142
 
 
182
 
183
  print('stack', stack)
184
 
185
+ return image, stack, state
186
 
187
 
188
  font_layout = ImageFont.truetype('./Arial.ttf', 16)
 
406
 
407
  with gr.Blocks() as demo:
408
 
409
+ #### for interactive
410
+ stack = []
411
+ state = 0
412
+
413
  gr.HTML(
414
  """
415
  <div style="text-align: center; max-width: 1600px; margin: 20px auto;">
 
450
  keywords = gr.Textbox(label="(Optional) Keywords. Should be seperated by / (e.g., keyword1/keyword2/...)", placeholder="keyword1/keyword2")
451
  positive_prompt = gr.Textbox(label="(Optional) Positive prompt", value=", digital art, very detailed, fantasy, high definition, cinematic light, dnd, trending on artstation")
452
 
453
+ # many encounter concurrent problem
454
+ with gr.Accordion("(Optional) Template - Click to paint", open=False):
455
+ with gr.Row():
456
+ with gr.Column(scale=1):
457
+ i = gr.Image(label="Canvas", type='filepath', value=f'./gray256.jpg', height=256, width=256)
458
+ with gr.Column(scale=1):
459
+ t = gr.Textbox(label="Keyword", value='input_keyword')
460
+ redo = gr.Button(value='Redo - Cancel the last keyword')
461
+ undo = gr.Button(value='Undo - Clear the canvas')
462
+ skip_button = gr.Button(value='Skip - Operate the next keyword')
463
+
464
+ i.select(get_pixels,[i,t,stack,state],[i,stack,state])
465
+ redo.click(exe_redo, [i,t,stack,state],[i,stack,state])
466
+ undo.click(exe_undo, [i,t,stack,state],[i,stack,state])
467
+ skip_button.click(skip_fun, [i,t,stack,state], [i,stack,state])
468
 
469
  radio = gr.Radio(["TextDiffuser-2", "TextDiffuser-2-LCM"], label="Choice of models", value="TextDiffuser-2")
470
  slider_natural = gr.Checkbox(label="Natural image generation", value=False, info="The text position and content info will not be incorporated.")