Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,12 +15,11 @@ model = AutoModelForCausalLM.from_pretrained("gpt2")
|
|
15 |
# Initialize TTS model
|
16 |
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
|
17 |
|
18 |
-
# Initialize Stable Diffusion pipeline
|
19 |
-
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.
|
20 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
21 |
pipe = pipe.to("cpu")
|
22 |
|
23 |
-
|
24 |
def generate_text(prompt, max_length=200):
|
25 |
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
26 |
attention_mask = torch.ones_like(input_ids)
|
@@ -32,16 +31,16 @@ def generate_speech(text):
|
|
32 |
tts.tts_to_file(text=text, file_path=output_path)
|
33 |
return output_path
|
34 |
|
35 |
-
def generate_video_frames(prompt, num_frames=
|
36 |
frames = []
|
37 |
for i in range(num_frames):
|
38 |
-
# Add some variation to the prompt for each frame
|
39 |
frame_prompt = f"{prompt}, frame {i+1} of {num_frames}"
|
40 |
-
|
|
|
41 |
frames.append(np.array(image))
|
42 |
return frames
|
43 |
|
44 |
-
def create_video_from_frames(frames, output_path="output_video.mp4", fps=
|
45 |
frames_tensor = torch.from_numpy(np.array(frames)).permute(0, 3, 1, 2)
|
46 |
write_video(output_path, frames_tensor, fps=fps)
|
47 |
return output_path
|
@@ -64,7 +63,7 @@ def generate_kids_music_animation(theme):
|
|
64 |
|
65 |
# Gradio Interface
|
66 |
with gr.Blocks() as app:
|
67 |
-
gr.Markdown("## AI-Generated Video and Audio Content")
|
68 |
|
69 |
with gr.Tab("Comedy Animation"):
|
70 |
comedy_prompt = gr.Textbox(label="Enter comedy prompt")
|
|
|
15 |
# Initialize TTS model
|
16 |
tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC")
|
17 |
|
18 |
+
# Initialize Stable Diffusion pipeline for CPU
|
19 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float32)
|
20 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
21 |
pipe = pipe.to("cpu")
|
22 |
|
|
|
23 |
def generate_text(prompt, max_length=200):
|
24 |
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
25 |
attention_mask = torch.ones_like(input_ids)
|
|
|
31 |
tts.tts_to_file(text=text, file_path=output_path)
|
32 |
return output_path
|
33 |
|
34 |
+
def generate_video_frames(prompt, num_frames=10):
|
35 |
frames = []
|
36 |
for i in range(num_frames):
|
|
|
37 |
frame_prompt = f"{prompt}, frame {i+1} of {num_frames}"
|
38 |
+
with torch.no_grad():
|
39 |
+
image = pipe(frame_prompt, num_inference_steps=20).images[0]
|
40 |
frames.append(np.array(image))
|
41 |
return frames
|
42 |
|
43 |
+
def create_video_from_frames(frames, output_path="output_video.mp4", fps=5):
|
44 |
frames_tensor = torch.from_numpy(np.array(frames)).permute(0, 3, 1, 2)
|
45 |
write_video(output_path, frames_tensor, fps=fps)
|
46 |
return output_path
|
|
|
63 |
|
64 |
# Gradio Interface
|
65 |
with gr.Blocks() as app:
|
66 |
+
gr.Markdown("## AI-Generated Video and Audio Content (CPU Version)")
|
67 |
|
68 |
with gr.Tab("Comedy Animation"):
|
69 |
comedy_prompt = gr.Textbox(label="Enter comedy prompt")
|