Spaces:
Running
on
Zero
Running
on
Zero
zR
commited on
Commit
·
9285448
1
Parent(s):
146d2aa
fix req
Browse files- app.py +19 -23
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import torch
|
| 4 |
from diffusers import CogVideoXPipeline
|
| 5 |
from diffusers.utils import export_to_video
|
| 6 |
-
from datetime import datetime
|
| 7 |
from openai import OpenAI
|
| 8 |
import spaces
|
| 9 |
import moviepy.editor as mp
|
|
@@ -94,7 +97,6 @@ def infer(
|
|
| 94 |
export_to_video(video, video_path)
|
| 95 |
return video_path
|
| 96 |
|
| 97 |
-
|
| 98 |
def convert_to_gif(video_path):
|
| 99 |
clip = mp.VideoFileClip(video_path)
|
| 100 |
clip = clip.set_fps(8)
|
|
@@ -103,6 +105,20 @@ def convert_to_gif(video_path):
|
|
| 103 |
clip.write_gif(gif_path, fps=8)
|
| 104 |
return gif_path
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
with gr.Blocks() as demo:
|
| 108 |
gr.Markdown("""
|
|
@@ -140,7 +156,6 @@ with gr.Blocks() as demo:
|
|
| 140 |
download_video_button = gr.File(label="📥 Download Video", visible=False)
|
| 141 |
download_gif_button = gr.File(label="📥 Download GIF", visible=False)
|
| 142 |
|
| 143 |
-
|
| 144 |
def generate(prompt, num_inference_steps, guidance_scale, progress=gr.Progress(track_tqdm=True)):
|
| 145 |
video_path = infer(prompt, num_inference_steps, guidance_scale, progress=progress)
|
| 146 |
video_update = gr.update(visible=True, value=video_path)
|
|
@@ -150,28 +165,9 @@ with gr.Blocks() as demo:
|
|
| 150 |
|
| 151 |
return video_path, video_update, gif_update
|
| 152 |
|
| 153 |
-
|
| 154 |
-
def enhance_prompt_func(prompt):
|
| 155 |
-
return convert_prompt(prompt, retry_times=1)
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
generate_button.click(
|
| 159 |
-
generate,
|
| 160 |
-
inputs=[prompt, num_inference_steps, guidance_scale],
|
| 161 |
-
outputs=[video_output, download_video_button, download_gif_button]
|
| 162 |
-
)
|
| 163 |
-
|
| 164 |
-
enhance_button.click(
|
| 165 |
-
enhance_prompt_func,
|
| 166 |
-
inputs=[prompt],
|
| 167 |
-
outputs=[prompt]
|
| 168 |
-
)
|
| 169 |
-
|
| 170 |
-
|
| 171 |
def enhance_prompt_func(prompt):
|
| 172 |
return convert_prompt(prompt, retry_times=1)
|
| 173 |
|
| 174 |
-
|
| 175 |
generate_button.click(
|
| 176 |
generate,
|
| 177 |
inputs=[prompt, num_inference_steps, guidance_scale],
|
|
@@ -185,4 +181,4 @@ with gr.Blocks() as demo:
|
|
| 185 |
)
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|
| 188 |
-
demo.launch(server_name="127.0.0.1", server_port=7860, share=True)
|
|
|
|
| 1 |
import os
|
| 2 |
+
import threading
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
import gradio as gr
|
| 6 |
import torch
|
| 7 |
from diffusers import CogVideoXPipeline
|
| 8 |
from diffusers.utils import export_to_video
|
| 9 |
+
from datetime import datetime, timedelta
|
| 10 |
from openai import OpenAI
|
| 11 |
import spaces
|
| 12 |
import moviepy.editor as mp
|
|
|
|
| 97 |
export_to_video(video, video_path)
|
| 98 |
return video_path
|
| 99 |
|
|
|
|
| 100 |
def convert_to_gif(video_path):
|
| 101 |
clip = mp.VideoFileClip(video_path)
|
| 102 |
clip = clip.set_fps(8)
|
|
|
|
| 105 |
clip.write_gif(gif_path, fps=8)
|
| 106 |
return gif_path
|
| 107 |
|
| 108 |
+
def delete_old_files():
|
| 109 |
+
while True:
|
| 110 |
+
now = datetime.now()
|
| 111 |
+
cutoff = now - timedelta(minutes=10)
|
| 112 |
+
output_dir = './output'
|
| 113 |
+
for filename in os.listdir(output_dir):
|
| 114 |
+
file_path = os.path.join(output_dir, filename)
|
| 115 |
+
if os.path.isfile(file_path):
|
| 116 |
+
file_mtime = datetime.fromtimestamp(os.path.getmtime(file_path))
|
| 117 |
+
if file_mtime < cutoff:
|
| 118 |
+
os.remove(file_path)
|
| 119 |
+
time.sleep(600) # Sleep for 10 minutes
|
| 120 |
+
|
| 121 |
+
threading.Thread(target=delete_old_files, daemon=True).start()
|
| 122 |
|
| 123 |
with gr.Blocks() as demo:
|
| 124 |
gr.Markdown("""
|
|
|
|
| 156 |
download_video_button = gr.File(label="📥 Download Video", visible=False)
|
| 157 |
download_gif_button = gr.File(label="📥 Download GIF", visible=False)
|
| 158 |
|
|
|
|
| 159 |
def generate(prompt, num_inference_steps, guidance_scale, progress=gr.Progress(track_tqdm=True)):
|
| 160 |
video_path = infer(prompt, num_inference_steps, guidance_scale, progress=progress)
|
| 161 |
video_update = gr.update(visible=True, value=video_path)
|
|
|
|
| 165 |
|
| 166 |
return video_path, video_update, gif_update
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
def enhance_prompt_func(prompt):
|
| 169 |
return convert_prompt(prompt, retry_times=1)
|
| 170 |
|
|
|
|
| 171 |
generate_button.click(
|
| 172 |
generate,
|
| 173 |
inputs=[prompt, num_inference_steps, guidance_scale],
|
|
|
|
| 181 |
)
|
| 182 |
|
| 183 |
if __name__ == "__main__":
|
| 184 |
+
demo.launch(server_name="127.0.0.1", server_port=7860, share=True)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
gradio==4.40.0
|
| 2 |
imageio-ffmpeg==0.5.1
|
| 3 |
torch==2.4.0
|
| 4 |
-
diffusers
|
| 5 |
spaces==0.29.2
|
| 6 |
moviepy==1.0.3
|
|
|
|
| 1 |
gradio==4.40.0
|
| 2 |
imageio-ffmpeg==0.5.1
|
| 3 |
torch==2.4.0
|
| 4 |
+
git+https://github.com/huggingface/diffusers.git@9c6b8894ff3f2a1aa000e2e1faf3291aa7a4f3e5#egg=diffusers
|
| 5 |
spaces==0.29.2
|
| 6 |
moviepy==1.0.3
|