pakokse commited on
Commit
d3bb50f
·
verified ·
1 Parent(s): 6b67eb9
Files changed (1) hide show
  1. app.py +21 -11
app.py CHANGED
@@ -5,23 +5,33 @@ import moviepy.editor as mp
5
  import os
6
 
7
  def generate_image(prompt):
8
- model_id = "runwayml/stable-diffusion-v1-5"
9
- pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
10
- pipe.to("cpu")
11
- image = pipe(prompt).images[0]
12
- image_path = "generated_image.png"
13
- image.save(image_path)
14
- return image_path
 
 
 
15
 
16
  def create_video(image_path, output_video="output.mp4", duration=5):
17
- clip = mp.ImageClip(image_path, duration=duration)
18
- clip = clip.set_fps(24)
19
- clip.write_videofile(output_video, codec='libx264')
20
- return output_video
 
 
 
21
 
22
  def text_to_video(prompt):
23
  image_path = generate_image(prompt)
 
 
24
  video_path = create_video(image_path)
 
 
25
  return video_path
26
 
27
  demo = gr.Interface(
 
5
  import os
6
 
7
  def generate_image(prompt):
8
+ try:
9
+ model_id = "runwayml/stable-diffusion-v1-5"
10
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float32)
11
+ pipe.to("cpu")
12
+ image = pipe(prompt).images[0]
13
+ image_path = "generated_image.png"
14
+ image.save(image_path)
15
+ return image_path
16
+ except Exception as e:
17
+ return f"Error generating image: {str(e)}"
18
 
19
  def create_video(image_path, output_video="output.mp4", duration=5):
20
+ try:
21
+ clip = mp.ImageClip(image_path, duration=duration)
22
+ clip = clip.set_fps(24)
23
+ clip.write_videofile(output_video, codec='libx264')
24
+ return output_video
25
+ except Exception as e:
26
+ return f"Error creating video: {str(e)}"
27
 
28
  def text_to_video(prompt):
29
  image_path = generate_image(prompt)
30
+ if "Error" in image_path:
31
+ return image_path
32
  video_path = create_video(image_path)
33
+ if "Error" in video_path:
34
+ return video_path
35
  return video_path
36
 
37
  demo = gr.Interface(