cocoat commited on
Commit
c7feaa8
·
verified ·
1 Parent(s): 5bbed8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -12
app.py CHANGED
@@ -101,14 +101,13 @@ def infer(
101
  history.insert(0, (img, caption))
102
  progress(1.0, desc="Done!")
103
 
104
- # Gallery用の画像リスト、State用のキャプションリスト
105
  images = [item[0] for item in history]
106
  captions = [item[1] for item in history]
107
  return img, images, captions
108
 
109
  # 選択コールバック
110
  def on_select(evt: gr.SelectData, captions):
111
- # evt.value は PIL.Image, evt.index は選択位置
112
  return evt.value, make_html_table(captions[evt.index])
113
 
114
  # CSS設定
@@ -132,22 +131,36 @@ with gr.Blocks(css=css) as demo:
132
  height = gr.Slider(256, MAX_SIZE, step=32, value=512, label="Height")
133
  cfg = gr.Slider(1.0, 30.0, step=0.1, value=7.5, label="CFG Scale")
134
  steps = gr.Slider(1, 50, step=1, value=12, label="Steps")
135
- scheduler_type = gr.Radio(choices=["Euler Ancestral", "DPM++ 2M SDE"],
136
- value="Euler Ancestral", label="Scheduler")
 
 
 
137
  run = gr.Button("Generate")
138
  img_out = gr.Image()
139
  table_html = gr.HTML()
140
  state = gr.State([])
141
- history_gallery = gr.Gallery(label="生成履歴", columns=4, height=300,
142
- show_label=True, interactive=True, type="pil", show_upload_button=False)
 
 
 
 
 
 
 
143
 
144
  # イベント設定
145
- run.click(fn=infer,
146
- inputs=[prompt, neg, seed_sl, rand, width, height, cfg, steps, scheduler_type],
147
- outputs=[img_out, history_gallery, state])
148
- history_gallery.select(fn=on_select,
149
- inputs=[state],
150
- outputs=[img_out, table_html])
 
 
 
 
151
 
152
  demo.queue()
153
  demo.launch()
 
101
  history.insert(0, (img, caption))
102
  progress(1.0, desc="Done!")
103
 
104
+ # Gallery用とState用リスト
105
  images = [item[0] for item in history]
106
  captions = [item[1] for item in history]
107
  return img, images, captions
108
 
109
  # 選択コールバック
110
  def on_select(evt: gr.SelectData, captions):
 
111
  return evt.value, make_html_table(captions[evt.index])
112
 
113
  # CSS設定
 
131
  height = gr.Slider(256, MAX_SIZE, step=32, value=512, label="Height")
132
  cfg = gr.Slider(1.0, 30.0, step=0.1, value=7.5, label="CFG Scale")
133
  steps = gr.Slider(1, 50, step=1, value=12, label="Steps")
134
+ scheduler_type = gr.Radio(
135
+ choices=["Euler Ancestral", "DPM++ 2M SDE"],
136
+ value="Euler Ancestral",
137
+ label="Scheduler"
138
+ )
139
  run = gr.Button("Generate")
140
  img_out = gr.Image()
141
  table_html = gr.HTML()
142
  state = gr.State([])
143
+ history_gallery = gr.Gallery(
144
+ label="生成履歴",
145
+ columns=4,
146
+ height=300,
147
+ show_label=True,
148
+ interactive=True,
149
+ type="pil",
150
+ show_upload_button=False
151
+ )
152
 
153
  # イベント設定
154
+ run.click(
155
+ fn=infer,
156
+ inputs=[prompt, neg, seed_sl, rand, width, height, cfg, steps, scheduler_type],
157
+ outputs=[img_out, history_gallery, state]
158
+ )
159
+ history_gallery.select(
160
+ fn=on_select,
161
+ inputs=[state],
162
+ outputs=[img_out, table_html]
163
+ )
164
 
165
  demo.queue()
166
  demo.launch()