ginipick commited on
Commit
6227e8c
·
verified ·
1 Parent(s): 993edef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -46,14 +46,15 @@ os.makedirs(GALLERY_DIR, exist_ok=True)
46
 
47
  def save_to_gallery(video_path, prompt):
48
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
49
- new_video_path = os.path.join(GALLERY_DIR, f"{timestamp}.mp4")
 
50
 
51
  # 비디오 파일 복사
52
  shutil.copy2(video_path, new_video_path)
53
 
54
  # 갤러리 정보 저장
55
  gallery_info = {
56
- "video": new_video_path,
57
  "prompt": prompt,
58
  "timestamp": timestamp
59
  }
@@ -70,7 +71,7 @@ def save_to_gallery(video_path, prompt):
70
  json.dump(gallery, f, indent=2)
71
 
72
  return new_video_path
73
-
74
  def load_gallery():
75
  if os.path.exists(GALLERY_JSON):
76
  with open(GALLERY_JSON, "r") as f:
@@ -78,8 +79,7 @@ def load_gallery():
78
  return [(item["video"], item["prompt"]) for item in reversed(gallery)]
79
  return []
80
 
81
- def update_gallery():
82
- return load_gallery()
83
 
84
  def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
85
  logging.info(f"Received prompt: {prompt}, steps: {steps}, cfg_scale: {cfg_scale}, "
@@ -187,21 +187,29 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
187
  )
188
 
189
  with gr.Tab("Gallery"):
190
- gallery = gr.Gallery(
191
- label="Generated Videos",
192
- show_label=False,
193
- elem_id="gallery",
194
- columns=[5],
195
- rows=[3],
196
- object_fit="contain",
197
- height="auto"
198
- )
199
  selected_video = gr.Video(label="Selected Video")
200
  refresh_btn = gr.Button("Refresh Gallery")
201
 
202
- refresh_btn.click(fn=update_gallery, inputs=None, outputs=gallery)
203
- demo.load(fn=update_gallery, inputs=None, outputs=gallery)
204
- gallery.select(show_video, None, selected_video)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
 
206
  input_text.submit(
207
  fn=respond,
 
46
 
47
  def save_to_gallery(video_path, prompt):
48
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
49
+ new_video_name = f"{timestamp}.mp4"
50
+ new_video_path = os.path.join(GALLERY_DIR, new_video_name)
51
 
52
  # 비디오 파일 복사
53
  shutil.copy2(video_path, new_video_path)
54
 
55
  # 갤러리 정보 저장
56
  gallery_info = {
57
+ "video": f"/file={new_video_path}", # 상대 경로 사용
58
  "prompt": prompt,
59
  "timestamp": timestamp
60
  }
 
71
  json.dump(gallery, f, indent=2)
72
 
73
  return new_video_path
74
+
75
  def load_gallery():
76
  if os.path.exists(GALLERY_JSON):
77
  with open(GALLERY_JSON, "r") as f:
 
79
  return [(item["video"], item["prompt"]) for item in reversed(gallery)]
80
  return []
81
 
82
+
 
83
 
84
  def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
85
  logging.info(f"Received prompt: {prompt}, steps: {steps}, cfg_scale: {cfg_scale}, "
 
187
  )
188
 
189
  with gr.Tab("Gallery"):
190
+ gallery_html = gr.HTML()
 
 
 
 
 
 
 
 
191
  selected_video = gr.Video(label="Selected Video")
192
  refresh_btn = gr.Button("Refresh Gallery")
193
 
194
+ def update_gallery():
195
+ gallery_items = load_gallery()
196
+ html = "<div style='display: flex; flex-wrap: wrap;'>"
197
+ for video_path, prompt in gallery_items:
198
+ html += f"""
199
+ <div style='margin: 10px; text-align: center;'>
200
+ <video width='200' height='200' controls>
201
+ <source src='{video_path}' type='video/mp4'>
202
+ </video>
203
+ <p>{prompt[:50]}...</p>
204
+ </div>
205
+ """
206
+ html += "</div>"
207
+ return html
208
+
209
+ refresh_btn.click(fn=update_gallery, inputs=None, outputs=gallery_html)
210
+ demo.load(fn=update_gallery, inputs=None, outputs=gallery_html)
211
+
212
+
213
 
214
  input_text.submit(
215
  fn=respond,