mikegarts commited on
Commit
5123446
·
1 Parent(s): a267f88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -64,6 +64,7 @@ def generate_story(prompt):
64
  return story, summary, gr.update(visible=True)
65
 
66
  def on_change_event(app_state):
 
67
  if app_state and app_state['running'] and app_state['img']:
68
  img = app_state['img']
69
  step = app_state['step']
@@ -71,9 +72,11 @@ def on_change_event(app_state):
71
  print(f'Updating the image:! {app_state}')
72
  app_state['dots'] += 1
73
  app_state['dots'] = app_state['dots'] % 10
74
- return gr.update(value=app_state['img_list'], label='intermediate steps'), app_state['staus_msg'] + '.' * app_state['dots']
 
 
75
  else:
76
- return gr.update(label='images list'), ''
77
 
78
  with gr.Blocks() as demo:
79
 
@@ -92,13 +95,13 @@ with gr.Blocks() as demo:
92
  app_state['step'] = step
93
  app_state['img_list'].append(res)
94
  app_state['status_msg'] = f'Generating state {step}'
95
- app_state['dots'] = 0
96
 
97
  prompt = prompt + ' masterpiece charcoal pencil art lord of the rings illustration'
98
  img = pipe(prompt, height=512, width=512, num_inference_steps=inference_steps, callback=callback, callback_steps=1)
99
  app_state['running'] = False
100
  app_state['img'] = None
101
  app_state['status_msg'] = ''
 
102
  return gr.update(value=img.images[0], label='Generated image')
103
 
104
  app_state = gr.State({'img': None,
@@ -122,7 +125,7 @@ with gr.Blocks() as demo:
122
  img_description = gr.Markdown('Image generation takes some time'
123
  ' but here you can see what is generated from the latent state of the diffuser every few steps.'
124
  ' Usually there is a significant improvement around step 12 that yields a much better image')
125
- status_msg = gr.Markdown(label='')
126
 
127
  gallery = gr.Gallery()
128
  image = gr.Image(label='Illustration for your story', show_label=True)
@@ -140,11 +143,12 @@ with gr.Blocks() as demo:
140
  bt_make_image.click(fn=generate_image, inputs=[summary, inference_steps, app_state], outputs=image)
141
 
142
  eventslider = gr.Slider(visible=False)
143
- dep = demo.load(on_change_event, app_state, [gallery, status_msg], every=10)
144
- eventslider.change(fn=on_change_event, inputs=[app_state], outputs=[gallery, status_msg], every=10, cancels=[dep])
145
 
146
 
147
  if READ_TOKEN:
148
  demo.queue().launch()
149
  else:
150
  demo.queue().launch(share=True, debug=True)
 
 
64
  return story, summary, gr.update(visible=True)
65
 
66
  def on_change_event(app_state):
67
+ print(f'on_change_event {app_state}')
68
  if app_state and app_state['running'] and app_state['img']:
69
  img = app_state['img']
70
  step = app_state['step']
 
72
  print(f'Updating the image:! {app_state}')
73
  app_state['dots'] += 1
74
  app_state['dots'] = app_state['dots'] % 10
75
+ message = app_state['status_msg'] + '.' * app_state['dots']
76
+ print (f'message={message}')
77
+ return gr.update(value=app_state['img_list'], label='intermediate steps'), gr.update(value=message)
78
  else:
79
+ return gr.update(label='images list'), gr.update(value='')
80
 
81
  with gr.Blocks() as demo:
82
 
 
95
  app_state['step'] = step
96
  app_state['img_list'].append(res)
97
  app_state['status_msg'] = f'Generating state {step}'
 
98
 
99
  prompt = prompt + ' masterpiece charcoal pencil art lord of the rings illustration'
100
  img = pipe(prompt, height=512, width=512, num_inference_steps=inference_steps, callback=callback, callback_steps=1)
101
  app_state['running'] = False
102
  app_state['img'] = None
103
  app_state['status_msg'] = ''
104
+ app_state['dots'] = 0
105
  return gr.update(value=img.images[0], label='Generated image')
106
 
107
  app_state = gr.State({'img': None,
 
125
  img_description = gr.Markdown('Image generation takes some time'
126
  ' but here you can see what is generated from the latent state of the diffuser every few steps.'
127
  ' Usually there is a significant improvement around step 12 that yields a much better image')
128
+ status_msg = gr.Markdown()
129
 
130
  gallery = gr.Gallery()
131
  image = gr.Image(label='Illustration for your story', show_label=True)
 
143
  bt_make_image.click(fn=generate_image, inputs=[summary, inference_steps, app_state], outputs=image)
144
 
145
  eventslider = gr.Slider(visible=False)
146
+ dep = demo.load(on_change_event, app_state, [gallery, status_msg], every=5)
147
+ eventslider.change(fn=on_change_event, inputs=[app_state], outputs=[gallery, status_msg], every=5, cancels=[dep])
148
 
149
 
150
  if READ_TOKEN:
151
  demo.queue().launch()
152
  else:
153
  demo.queue().launch(share=True, debug=True)
154
+