AI_Comedy_Show / app.py
Manasa1's picture
Update app.py
dbe4319 verified
raw
history blame
1.73 kB
import gradio as gr
from transformers import pipeline
from pydub.generators import Sine
from pydub import AudioSegment
# Load pre-trained Hugging Face text generation model for comedy scripts
script_generator = pipeline("text-generation", model="gpt2")
# Function to generate a kids' music track using Sine waves
def generate_kids_music(theme):
# Use sine wave for simple tone-based music
frequencies = [220, 247, 262, 294, 330, 349] # A sequence of basic notes (Hz)
duration_per_note = 500 # 0.5 seconds per note
song = AudioSegment.silent(duration=0)
# Generate a basic sequence of notes
for freq in frequencies:
sine_wave = Sine(freq).to_audio_segment(duration=duration_per_note)
song += sine_wave
# Export the generated song
file_path = f"kids_music_{theme}.mp3"
song.export(file_path, format="mp3")
return file_path
# Function to generate a comedy script using GPT-2
def generate_comedy_script(prompt):
result = script_generator(prompt, max_length=100, num_return_sequences=1)
return result[0]["generated_text"]
# Gradio interface
def generate_music_and_comedy(theme, prompt):
music_file = generate_kids_music(theme)
script = generate_comedy_script(prompt)
return script, music_file
# Gradio interface
demo = gr.Interface(
fn=generate_music_and_comedy,
inputs=[gr.Textbox(label="Music Theme"), gr.Textbox(label="Comedy Prompt")],
outputs=[gr.Textbox(label="Generated Comedy Script"), gr.Audio(label="Generated Kids Music")],
title="AI Kids Music and Comedy Generator",
description="Generate kids' music based on a theme and comedy scripts based on a prompt.",
)
if __name__ == "__main__":
demo.launch()