Unseenseven commited on
Commit
2a58b6a
1 Parent(s): 035536e

Fixed merge conflict markers and enhanced gradio interface

Browse files
Files changed (1) hide show
  1. gradio_interface_extended.py +10 -15
gradio_interface_extended.py CHANGED
@@ -9,14 +9,13 @@ def generate_video(prompt, duration, frame_rate, music_file):
9
  # Initialize the pipeline
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
  if device == "cuda":
12
- pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
13
  else:
14
- pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
15
-
16
- pipeline = pipeline.to(device)
17
 
18
  # Generate frames
19
- num_frames = duration * frame_rate
20
  temp_dir = f"/tmp/{datetime.now().strftime('%Y%m%d%H%M%S')}"
21
  os.makedirs(temp_dir, exist_ok=True)
22
 
@@ -27,13 +26,13 @@ def generate_video(prompt, duration, frame_rate, music_file):
27
 
28
  # Create video from frames
29
  video_path = os.path.join(temp_dir, "video.mp4")
30
- video_clip = mp.ImageSequenceClip(temp_dir, fps=frame_rate)
31
-
32
  if music_file:
33
  audio_clip = mp.AudioFileClip(music_file)
34
  audio_clip = audio_clip.set_duration(video_clip.duration)
35
  video_clip = video_clip.set_audio(audio_clip)
36
-
37
  video_clip.write_videofile(video_path, codec="libx264")
38
 
39
  return video_path
@@ -41,27 +40,23 @@ def generate_video(prompt, duration, frame_rate, music_file):
41
  with gr.Blocks() as demo:
42
  gr.Markdown("# AI Dreams & Visions Video Generator")
43
  gr.Markdown("Generate stunning videos from text prompts using AI technology. For inquiries, contact us at [aidreams@aidreams.company](mailto:aidreams@aidreams.company). Follow us on X: [@TheKingofJewelz](https://x.com/TheKingofJewelz).")
44
-
45
  with gr.Row():
46
  with gr.Column():
47
  prompt = gr.Textbox(label="Text Prompt", placeholder="Enter your video description here...")
48
  duration = gr.Slider(label="Duration (seconds)", minimum=1, maximum=30, step=1, value=5)
49
  frame_rate = gr.Slider(label="Frame Rate", minimum=1, maximum=60, step=1, value=24)
50
- music_file = gr.Audio(label="Music File (Optional)", type="filepath")
51
  generate_btn = gr.Button("Generate Video")
52
 
53
  with gr.Column():
54
  video_output = gr.Video(label="Generated Video")
55
  download_link = gr.File(label="Download Video")
56
 
57
- def generate_and_display_video(prompt, duration, frame_rate, music_file):
58
- video_path = generate_video(prompt, duration, frame_rate, music_file)
59
- return video_path, video_path
60
-
61
  generate_btn.click(
62
  generate_and_display_video,
63
  inputs=[prompt, duration, frame_rate, music_file],
64
- outputs=[video_output, download_link],
65
  )
66
 
67
  if __name__ == "__main__":
 
9
  # Initialize the pipeline
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
  if device == "cuda":
12
+ pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16).to(device)
13
  else:
14
+ # Use float32 when running on CPU
15
+ pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4").to(device)
 
16
 
17
  # Generate frames
18
+ num_frames = int(duration * frame_rate)
19
  temp_dir = f"/tmp/{datetime.now().strftime('%Y%m%d%H%M%S')}"
20
  os.makedirs(temp_dir, exist_ok=True)
21
 
 
26
 
27
  # Create video from frames
28
  video_path = os.path.join(temp_dir, "video.mp4")
29
+ video_clip = mp.ImageSequenceClip([os.path.join(temp_dir, f"frame_{i:04d}.png") for i in range(num_frames)], fps=frame_rate)
30
+
31
  if music_file:
32
  audio_clip = mp.AudioFileClip(music_file)
33
  audio_clip = audio_clip.set_duration(video_clip.duration)
34
  video_clip = video_clip.set_audio(audio_clip)
35
+
36
  video_clip.write_videofile(video_path, codec="libx264")
37
 
38
  return video_path
 
40
  with gr.Blocks() as demo:
41
  gr.Markdown("# AI Dreams & Visions Video Generator")
42
  gr.Markdown("Generate stunning videos from text prompts using AI technology. For inquiries, contact us at [aidreams@aidreams.company](mailto:aidreams@aidreams.company). Follow us on X: [@TheKingofJewelz](https://x.com/TheKingofJewelz).")
43
+
44
  with gr.Row():
45
  with gr.Column():
46
  prompt = gr.Textbox(label="Text Prompt", placeholder="Enter your video description here...")
47
  duration = gr.Slider(label="Duration (seconds)", minimum=1, maximum=30, step=1, value=5)
48
  frame_rate = gr.Slider(label="Frame Rate", minimum=1, maximum=60, step=1, value=24)
49
+ music_file = gr.Audio(label="Music File (Optional)", type="file")
50
  generate_btn = gr.Button("Generate Video")
51
 
52
  with gr.Column():
53
  video_output = gr.Video(label="Generated Video")
54
  download_link = gr.File(label="Download Video")
55
 
 
 
 
 
56
  generate_btn.click(
57
  generate_and_display_video,
58
  inputs=[prompt, duration, frame_rate, music_file],
59
+ outputs=[video_output, download_link]
60
  )
61
 
62
  if __name__ == "__main__":