File size: 4,556 Bytes
5b0d83d
dbe4319
ac48b9a
ad7dc96
dbe4319
ac48b9a
5b0d83d
dbe4319
 
5b0d83d
dbe4319
22c8d3b
 
 
 
dbe4319
96f47bd
 
 
 
 
 
 
 
 
ac48b9a
22c8d3b
 
 
 
ad7dc96
22c8d3b
 
 
 
ad7dc96
 
22c8d3b
 
 
ad7dc96
ac48b9a
3dc8327
 
 
 
 
 
 
 
 
 
ac48b9a
3dc8327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac48b9a
 
 
3dc8327
ad7dc96
ac48b9a
 
dbe4319
ac48b9a
 
ad7dc96
 
 
ac48b9a
 
 
 
 
 
1b406ee
ac48b9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dbe4319
5b0d83d
ad7dc96
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import gradio as gr
from transformers import pipeline
import pyttsx3
from moviepy.editor import TextClip, CompositeVideoClip, concatenate_videoclips
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
from transformers import pipeline

script_generator = pipeline("text-generation", model="gpt2", truncation=True, max_length=100)  # Adjust max_length as needed


from gtts import gTTS
import os

def text_to_speech(script):
    tts = gTTS(text=script, lang='en')
    audio_file = "output.mp3"
    tts.save(audio_file)
    return audio_file


from moviepy.editor import TextClip

def generate_animation(script):
    lines = script.split('\n')
    clips = []

    for line in lines:
        text_clip = TextClip(line, fontsize=40, color='white', size=(800, 400), bg_color='black', method='caption', print_cmd=True)
        text_clip = text_clip.set_duration(3)  # Set duration for each clip
        clips.append(text_clip)

    # Concatenate all text clips into one video clip
    final_video = concatenate_videoclips(clips)
    return final_video


import numpy as np
from scipy.io.wavfile import write
from pydub import AudioSegment

def generate_sine_wave(frequency, duration, sample_rate=44100, amplitude=0.5):
    """Generate a sine wave."""
    t = np.linspace(0, duration, int(sample_rate * duration), False)
    wave = amplitude * np.sin(2 * np.pi * frequency * t)
    return wave

def generate_kids_music(theme, output_music_file="kids_music.wav"):
    # Generate a sine wave for C4, D4, E4 notes
    sample_rate = 44100
    duration = 2  # 2 seconds per note
    
    c4_wave = generate_sine_wave(261.63, duration)  # C4
    d4_wave = generate_sine_wave(293.66, duration)  # D4
    e4_wave = generate_sine_wave(329.63, duration)  # E4
    
    # Combine the waves
    wave = np.concatenate([c4_wave, d4_wave, e4_wave])
    
    # Normalize to 16-bit PCM format
    audio_wave = np.int16(wave * 32767)
    
    # Save as a wav file
    write(output_music_file, sample_rate, audio_wave)
    
    # Convert to AudioSegment (optional if you need to modify)
    audio_segment = AudioSegment.from_wav(output_music_file)
    
    return output_music_file


# Function to combine kids music with a simple 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)
    clips = [TextClip("Kids Music: " + theme, fontsize=70, color='yellow', size=(800, 400), bg_color='blue', method='caption').set_duration(5)]
    video = CompositeVideoClip(clips)
    video.write_videofile(output_video_file, fps=24)
    
    return output_video_file, music_file

# Gradio interface to bring everything together
def generate_comedy_and_animation(prompt):
    # Comedy Script Generation
    script = script_generator(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()