File size: 4,115 Bytes
5b0d83d
dbe4319
ac48b9a
 
dbe4319
ac48b9a
5b0d83d
dbe4319
 
5b0d83d
dbe4319
 
ac48b9a
dbe4319
 
ac48b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbe4319
ac48b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbe4319
ac48b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbe4319
5b0d83d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import gradio as gr
from transformers import pipeline
import pyttsx3
from manim import Scene, Text, Write, config
from pydub import AudioSegment
import os

# Load pre-trained Hugging Face text generation model for comedy scripts
script_generator = pipeline("text-generation", model="gpt2")

# Function to generate a comedy script using GPT-2
def generate_comedy_script(prompt):
    result = script_generator(prompt, max_length=150, num_return_sequences=1)
    return result[0]["generated_text"]

# Text-to-Speech (TTS) using pyttsx3 for comedy
def text_to_speech(script, output_audio_file="script_audio.mp3"):
    engine = pyttsx3.init()
    engine.save_to_file(script, output_audio_file)
    engine.runAndWait()
    return output_audio_file

# Function to generate animated video using Manim (for comedy script)
def generate_animation(script, output_video_file="animated_script.mp4"):
    class ScriptAnimation(Scene):
        def construct(self):
            # Create a text object and animate it
            script_text = Text(script[:200])  # Limited text for simplicity
            self.play(Write(script_text))
    
    config.media_dir = "./media"
    config.output_file = output_video_file
    animation = ScriptAnimation()
    animation.render()
    
    return os.path.join(config.media_dir, "videos", output_video_file)

# Function to generate simple music (for kids content)
def generate_kids_music(theme, output_music_file="kids_music.wav"):
    # Simple sine wave generation using pydub for kids' music
    music = AudioSegment.sine(frequency=261.63)  # C4 note
    music += AudioSegment.sine(frequency=293.66)  # D4 note
    music += AudioSegment.sine(frequency=329.63)  # E4 note
    
    # Extend for more complexity, then export
    music.export(output_music_file, format="wav")
    return output_music_file

# Function to combine kids music with an animation
def generate_kids_animation_with_music(theme, output_video_file="kids_animation.mp4"):
    # Step 1: Generate kids music
    music_file = generate_kids_music(theme)
    
    # Step 2: Generate simple animation for the music (using text animation as a placeholder)
    class KidsMusicAnimation(Scene):
        def construct(self):
            music_text = Text("Kids Music: " + theme)
            self.play(Write(music_text))
    
    config.media_dir = "./media"
    config.output_file = output_video_file
    animation = KidsMusicAnimation()
    animation.render()
    
    return output_video_file, music_file

# Gradio interface to bring everything together
def generate_comedy_and_animation(prompt):
    # Comedy Script Generation
    script = generate_comedy_script(prompt)
    audio_file = text_to_speech(script)
    video_file = generate_animation(script)
    
    return script, audio_file, video_file

def generate_kids_content(theme):
    video_file, music_file = generate_kids_animation_with_music(theme)
    return music_file, video_file

# Gradio app for Comedy and Kids Content
with gr.Blocks() as app:
    gr.Markdown("## AI Comedy and Kids Content Generator")
    
    with gr.Tab("Generate Comedy Animation"):
        prompt_input = gr.Textbox(label="Comedy Prompt")
        generate_btn = gr.Button("Generate Comedy Script and Animation")
        comedy_script = gr.Textbox(label="Generated Script")
        comedy_audio = gr.Audio(label="Generated Audio")
        comedy_video = gr.Video(label="Generated Animation")
        
        generate_btn.click(
            generate_comedy_and_animation,
            inputs=prompt_input,
            outputs=[comedy_script, comedy_audio, comedy_video]
        )
    
    with gr.Tab("Generate Kids Music Animation"):
        theme_input = gr.Textbox(label="Kids Music Theme")
        generate_music_btn = gr.Button("Generate Kids Music and Animation")
        kids_music_audio = gr.Audio(label="Generated Music")
        kids_music_video = gr.Video(label="Generated Kids Animation")
        
        generate_music_btn.click(
            generate_kids_content,
            inputs=theme_input,
            outputs=[kids_music_audio, kids_music_video]
        )

app.launch()