Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +75 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
# Initialize the client with your API key and the CogVideoX-5B-Space endpoint
|
5 |
+
api_key = ""
|
6 |
+
client = Client("THUDM/CogVideoX-5B-Space", hf_token=api_key)
|
7 |
+
|
8 |
+
def generate_video(prompt, seed_value, scale_status, rife_status):
|
9 |
+
result = client.predict(
|
10 |
+
prompt=prompt,
|
11 |
+
seed_value=seed_value,
|
12 |
+
scale_status=scale_status,
|
13 |
+
rife_status=rife_status,
|
14 |
+
api_name="/generate"
|
15 |
+
)
|
16 |
+
|
17 |
+
video_url = result[0]['video']
|
18 |
+
subtitles = result[0]['subtitles']
|
19 |
+
video_file = result[1]
|
20 |
+
gif_file = result[2]
|
21 |
+
seed_used = result[3]
|
22 |
+
|
23 |
+
# Save video file locally
|
24 |
+
video_file_path = "generated_video.mp4"
|
25 |
+
with open(video_file_path, "wb") as f:
|
26 |
+
f.write(client.download_file(video_file))
|
27 |
+
|
28 |
+
# Save GIF file locally
|
29 |
+
gif_file_path = "generated_video.gif"
|
30 |
+
with open(gif_file_path, "wb") as f:
|
31 |
+
f.write(client.download_file(gif_file))
|
32 |
+
|
33 |
+
return video_url, gif_file_path, seed_used
|
34 |
+
|
35 |
+
def enhance_prompt(prompt):
|
36 |
+
enhanced_prompt = client.predict(
|
37 |
+
prompt=prompt,
|
38 |
+
api_name="/enhance_prompt_func"
|
39 |
+
)
|
40 |
+
return enhanced_prompt
|
41 |
+
|
42 |
+
def video_interface(prompt, seed_value=-1, scale_status=False, rife_status=False):
|
43 |
+
video_url, gif_file_path, seed_used = generate_video(prompt, seed_value, scale_status, rife_status)
|
44 |
+
return video_url, gif_file_path, seed_used
|
45 |
+
|
46 |
+
video_gen_interface = gr.Interface(
|
47 |
+
fn=video_interface,
|
48 |
+
inputs=[
|
49 |
+
gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
50 |
+
gr.Number(value=-1, label="Inference Seed (-1 for random)"),
|
51 |
+
gr.Checkbox(label="Super-Resolution (720 × 480 -> 1440 × 960)"),
|
52 |
+
gr.Checkbox(label="Frame Interpolation (8fps -> 16fps)")
|
53 |
+
],
|
54 |
+
outputs=[
|
55 |
+
gr.Video(label="Generated Video"),
|
56 |
+
gr.File(label="Download GIF"),
|
57 |
+
gr.Number(label="Seed Used for Video Generation")
|
58 |
+
],
|
59 |
+
title="Pettah AI: VideoGenX"
|
60 |
+
)
|
61 |
+
|
62 |
+
def enhance_interface(prompt):
|
63 |
+
enhanced_prompt = enhance_prompt(prompt)
|
64 |
+
return enhanced_prompt
|
65 |
+
|
66 |
+
enhance_prompt_interface = gr.Interface(
|
67 |
+
fn=enhance_interface,
|
68 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."),
|
69 |
+
outputs=gr.Textbox(lines=2),
|
70 |
+
title="Enhance Prompt with CogVideoX-5B"
|
71 |
+
)
|
72 |
+
|
73 |
+
if __name__ == "__main__":
|
74 |
+
video_gen_interface.launch(share=True)
|
75 |
+
enhance_prompt_interface.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
gradio_client
|