ginipick commited on
Commit
eb00a3f
·
verified ·
1 Parent(s): c210d6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -180,24 +180,31 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
180
 
181
 
182
  with gr.Tab("Gallery"):
183
- gallery_html = gr.HTML()
 
 
 
 
 
 
 
 
184
  selected_video = gr.Video(label="Selected Video")
185
  refresh_btn = gr.Button("Refresh Gallery")
186
 
187
  def update_gallery():
188
  gallery_items = load_gallery()
189
- html = "<div style='display: flex; flex-wrap: wrap;'>"
190
- for item in gallery_items:
191
- html += f"<div style='margin: 10px;'><video width='200' height='200' controls><source src='{item['image']}' type='video/mp4'></video><p>{item['caption']}</p></div>"
192
- html += "</div>"
193
- return html
194
 
195
  def show_video(evt: gr.SelectData):
196
- return evt.target.src
197
 
198
- refresh_btn.click(fn=update_gallery, inputs=None, outputs=gallery_html)
199
- demo.load(fn=update_gallery, inputs=None, outputs=gallery_html)
200
- gallery_html.click(show_video, None, selected_video)
201
 
202
  input_text.submit(
203
  fn=respond,
@@ -206,9 +213,8 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
206
  ).then(
207
  fn=update_gallery,
208
  inputs=None,
209
- outputs=gallery_html
210
  )
211
 
212
  if __name__ == "__main__":
213
  demo.launch()
214
-
 
180
 
181
 
182
  with gr.Tab("Gallery"):
183
+ gallery = gr.Gallery(
184
+ label="Generated Videos",
185
+ show_label=False,
186
+ elem_id="gallery",
187
+ columns=[5],
188
+ rows=[3],
189
+ object_fit="contain",
190
+ height="auto"
191
+ )
192
  selected_video = gr.Video(label="Selected Video")
193
  refresh_btn = gr.Button("Refresh Gallery")
194
 
195
  def update_gallery():
196
  gallery_items = load_gallery()
197
+ return [
198
+ (item['image'], item['caption'])
199
+ for item in gallery_items
200
+ ]
 
201
 
202
  def show_video(evt: gr.SelectData):
203
+ return evt.value[0] # 선택된 비디오의 경로 반환
204
 
205
+ refresh_btn.click(fn=update_gallery, inputs=None, outputs=gallery)
206
+ demo.load(fn=update_gallery, inputs=None, outputs=gallery)
207
+ gallery.select(show_video, None, selected_video)
208
 
209
  input_text.submit(
210
  fn=respond,
 
213
  ).then(
214
  fn=update_gallery,
215
  inputs=None,
216
+ outputs=gallery
217
  )
218
 
219
  if __name__ == "__main__":
220
  demo.launch()