import random from pydub import AudioSegment def generate_kids_music(theme): # Create a simple melody based on themes notes = { "birthday": ["C4", "E4", "G4", "C5"], "ocean": ["C4", "D4", "E4", "F4"], "adventure": ["E4", "G4", "A4", "C5"] } selected_notes = notes.get(theme, ["C4", "E4", "G4"]) # Default notes if theme not found music = AudioSegment.silent(duration=1000) # Start with 1 second of silence for note in selected_notes: # Generate a simple sine wave for each note frequency = 261.63 if note == "C4" else 329.63 if note == "E4" else 392.00 if note == "G4" else 523.25 sine_wave = AudioSegment.sine(frequency=frequency, duration=500) # 0.5 second for each note music += sine_wave # Export the generated music output_file = f"{theme}_kids_music.wav" music.export(output_file, format="wav") return output_file from transformers import pipeline # Load the GPT-2 model for text generation comedy_generator = pipeline('text-generation', model='gpt2') def generate_comedy_script(prompt): result = comedy_generator(prompt, max_length=150, num_return_sequences=1) return result[0]['generated_text'] from gtts import gTTS def script_to_audio(script): tts = gTTS(script, lang='en') audio_file = "comedy_script.mp3" tts.save(audio_file) return audio_file import gradio as gr def generate_music_and_comedy(theme, prompt): # Generate music music_file = generate_kids_music(theme) # Generate comedy script comedy_script = generate_comedy_script(prompt) # Convert the comedy script to audio audio_file = script_to_audio(comedy_script) return music_file, comedy_script, audio_file # Gradio Interface iface = gr.Interface( fn=generate_music_and_comedy, inputs=[ gr.Dropdown(choices=["birthday", "ocean", "adventure"], label="Select Theme for Kids' Music"), gr.Textbox(lines=2, placeholder="Enter a prompt for comedy...", label="Comedy Prompt") ], outputs=[ gr.Audio(label="Generated Kids' Music"), gr.Textbox(label="Generated Comedy Script"), gr.Audio(label="Comedy Audio") ], title="AI Music and Comedy Generator", description="Generate unique music for kids based on themes and comedic scripts from your prompts." ) # Launch the app iface.launch()