Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -47,19 +47,13 @@ os.makedirs(GALLERY_DIR, exist_ok=True)
|
|
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 |
-
thumbnail_path = os.path.join(GALLERY_DIR, f"{timestamp}_thumb.jpg")
|
51 |
|
52 |
# ๋น๋์ค ํ์ผ ๋ณต์ฌ
|
53 |
shutil.copy2(video_path, new_video_path)
|
54 |
|
55 |
-
# ์ธ๋ค์ผ ์์ฑ
|
56 |
-
video = VideoFileClip(new_video_path)
|
57 |
-
video.save_frame(thumbnail_path, t=0) # ์ฒซ ํ๋ ์์ ์ธ๋ค์ผ๋ก ์ ์ฅ
|
58 |
-
|
59 |
# ๊ฐค๋ฌ๋ฆฌ ์ ๋ณด ์ ์ฅ
|
60 |
gallery_info = {
|
61 |
"video": new_video_path,
|
62 |
-
"thumbnail": thumbnail_path,
|
63 |
"prompt": prompt,
|
64 |
"timestamp": timestamp
|
65 |
}
|
@@ -75,16 +69,15 @@ def save_to_gallery(video_path, prompt):
|
|
75 |
with open(GALLERY_JSON, "w") as f:
|
76 |
json.dump(gallery, f, indent=2)
|
77 |
|
78 |
-
return new_video_path
|
79 |
|
80 |
def load_gallery():
|
81 |
if os.path.exists(GALLERY_JSON):
|
82 |
with open(GALLERY_JSON, "r") as f:
|
83 |
gallery = json.load(f)
|
84 |
-
return [(item["
|
85 |
return []
|
86 |
|
87 |
-
|
88 |
def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
|
89 |
logging.info(f"Received prompt: {prompt}, steps: {steps}, cfg_scale: {cfg_scale}, "
|
90 |
f"eta: {eta}, fs: {fs}, seed: {seed}, video_length: {video_length}")
|
@@ -183,7 +176,6 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
183 |
inputs=[],
|
184 |
outputs=[input_text, input_image]
|
185 |
)
|
186 |
-
|
187 |
with gr.Tab("Gallery"):
|
188 |
gallery = gr.Gallery(
|
189 |
label="Generated Videos",
|
@@ -192,23 +184,24 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
|
192 |
columns=[5],
|
193 |
rows=[3],
|
194 |
object_fit="contain",
|
195 |
-
height="auto"
|
|
|
196 |
)
|
197 |
selected_video = gr.Video(label="Selected Video")
|
198 |
refresh_btn = gr.Button("Refresh Gallery")
|
199 |
-
|
200 |
|
201 |
def update_gallery():
|
202 |
return load_gallery()
|
203 |
|
204 |
def show_video(evt: gr.SelectData):
|
205 |
-
if isinstance(evt.value, tuple) and len(evt.value) >
|
206 |
-
return evt.value[0] # ์ฒซ ๋ฒ์งธ ์์๊ฐ ๋น๋์ค
|
207 |
elif isinstance(evt.value, str):
|
208 |
return evt.value # ๊ฐ์ด ์ง์ ๋น๋์ค ๊ฒฝ๋ก์ผ ์ ์์ต๋๋ค
|
209 |
else:
|
210 |
print(f"Unexpected evt.value structure: {evt.value}")
|
211 |
-
return None
|
212 |
|
213 |
refresh_btn.click(fn=update_gallery, inputs=None, outputs=gallery)
|
214 |
demo.load(fn=update_gallery, inputs=None, outputs=gallery)
|
|
|
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 |
}
|
|
|
69 |
with open(GALLERY_JSON, "w") as f:
|
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:
|
77 |
gallery = json.load(f)
|
78 |
+
return [(item["video"], item["prompt"]) for item in reversed(gallery)]
|
79 |
return []
|
80 |
|
|
|
81 |
def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
|
82 |
logging.info(f"Received prompt: {prompt}, steps: {steps}, cfg_scale: {cfg_scale}, "
|
83 |
f"eta: {eta}, fs: {fs}, seed: {seed}, video_length: {video_length}")
|
|
|
176 |
inputs=[],
|
177 |
outputs=[input_text, input_image]
|
178 |
)
|
|
|
179 |
with gr.Tab("Gallery"):
|
180 |
gallery = gr.Gallery(
|
181 |
label="Generated Videos",
|
|
|
184 |
columns=[5],
|
185 |
rows=[3],
|
186 |
object_fit="contain",
|
187 |
+
height="auto",
|
188 |
+
preview=True
|
189 |
)
|
190 |
selected_video = gr.Video(label="Selected Video")
|
191 |
refresh_btn = gr.Button("Refresh Gallery")
|
192 |
+
|
193 |
|
194 |
def update_gallery():
|
195 |
return load_gallery()
|
196 |
|
197 |
def show_video(evt: gr.SelectData):
|
198 |
+
if isinstance(evt.value, tuple) and len(evt.value) > 0:
|
199 |
+
return evt.value[0] # ์ฒซ ๋ฒ์งธ ์์๊ฐ ๋น๋์ค ๊ฒฝ๋ก์
๋๋ค
|
200 |
elif isinstance(evt.value, str):
|
201 |
return evt.value # ๊ฐ์ด ์ง์ ๋น๋์ค ๊ฒฝ๋ก์ผ ์ ์์ต๋๋ค
|
202 |
else:
|
203 |
print(f"Unexpected evt.value structure: {evt.value}")
|
204 |
+
return None
|
205 |
|
206 |
refresh_btn.click(fn=update_gallery, inputs=None, outputs=gallery)
|
207 |
demo.load(fn=update_gallery, inputs=None, outputs=gallery)
|