JingyeChen commited on
Commit
8487f87
1 Parent(s): 2c24e74
Files changed (1) hide show
  1. app.py +19 -22
app.py CHANGED
@@ -83,27 +83,28 @@ pipe.load_lora_weights(lcm_lora_id)
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,10 +134,10 @@ def exe_redo(i, t, stack, state):
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,7 +183,7 @@ def get_pixels(i, t, stack, state, evt: gr.SelectData):
182
 
183
  print('stack', stack)
184
 
185
- return image, stack, state
186
 
187
 
188
  font_layout = ImageFont.truetype('./Arial.ttf', 16)
@@ -406,10 +407,6 @@ def text_to_image(prompt,keywords,positive_prompt,radio,slider_step,slider_guida
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;">
@@ -461,10 +458,10 @@ with gr.Blocks() as demo:
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.")
 
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
  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
 
184
  print('stack', stack)
185
 
186
+ return image
187
 
188
 
189
  font_layout = ImageFont.truetype('./Arial.ttf', 16)
 
407
 
408
  with gr.Blocks() as demo:
409
 
 
 
 
 
410
  gr.HTML(
411
  """
412
  <div style="text-align: center; max-width: 1600px; margin: 20px auto;">
 
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.")