sivaprakash-rajendran commited on
Commit
bb8682e
·
1 Parent(s): d2d78c7

Initial Commit

Browse files
Files changed (2) hide show
  1. app.py +33 -26
  2. requirements.txt +2 -3
app.py CHANGED
@@ -1,31 +1,38 @@
1
  import gradio as gr
2
- from diffusers import DiffusionPipeline
3
-
4
- # Load the text-to-video model from Hugging Face (CogVideoX-5b)
5
- pipe = DiffusionPipeline.from_pretrained("THUDM/CogVideoX-5b")
6
-
7
- # Define a function that generates a video based on the input prompt
8
- def generate_video(prompt):
9
- # Generate video frames (or single image) based on the prompt
10
- result = pipe(prompt)
11
- if hasattr(result, "videos"):
12
- video = result.videos[0] # Access the first generated video if available
13
- return video
14
- elif hasattr(result, "images"):
15
- image = result.images[0] # Fallback to first generated image if video is not available
16
- return image
17
- else:
18
- return None
19
-
20
- # Create a Gradio Interface
21
- interface = gr.Interface(
 
 
 
 
 
 
 
 
22
  fn=generate_video,
23
- inputs=gr.Textbox(label="Enter a prompt for video generation", placeholder="Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"),
24
- outputs=gr.Video(label="Generated Video") if hasattr(pipe, "videos") else gr.Image(label="Generated Image"),
25
  title="Text-to-Video Generator",
26
- description="Generate a short video or image based on a textual prompt using Hugging Face's CogVideo model."
27
  )
28
 
29
- # Launch the app
30
- if __name__ == "__main__":
31
- interface.launch()
 
1
  import gradio as gr
2
+ from diffusers import CogVideoXPipeline # Import the appropriate text-to-video pipeline
3
+ import torch
4
+
5
+ # Load your text-to-video model (replace with the actual model)
6
+ model_name = "THUDM/CogVideoX-2b" # Example model name
7
+ device = "cuda" if torch.cuda.is_available() else "cpu" # Check for GPU availability
8
+
9
+ # Load the model
10
+ text_video_pipe = CogVideoXPipeline.from_pretrained(
11
+ model_name,
12
+ torch_dtype=torch.float16
13
+ ).to(device)
14
+
15
+ # Define the function for generating video from text
16
+ def generate_video(text_prompt):
17
+ # Generate the video using the text prompt
18
+ video = text_video_pipe(text_prompt, num_inference_steps=50, guidance_scale=7.5).videos
19
+
20
+ # Define the video file path to save the generated video
21
+ video_path = "generated_video.mp4"
22
+
23
+ # Save the video (you may need to adjust this depending on your pipeline's output)
24
+ video[0].save(video_path) # Assuming the output is a list of videos
25
+
26
+ return video_path
27
+
28
+ # Gradio Interface
29
+ iface = gr.Interface(
30
  fn=generate_video,
31
+ inputs="text",
32
+ outputs="video",
33
  title="Text-to-Video Generator",
34
+ description="Enter a prompt to generate a video."
35
  )
36
 
37
+ # Launch the Gradio app
38
+ iface.launch()
 
requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
- diffusers
2
  gradio
3
- torch
4
  transformers
5
- accelerate
 
 
 
1
  gradio
 
2
  transformers
3
+ torch
4
+ diffusers