# # kukubuddy_ai_light.py # import random # import gradio as gr # from transformers import pipeline # from TTS.api import TTS # # Small & memory-efficient models # summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # story_gen = pipeline("text2text-generation", model="google/flan-t5-small") # tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False) # # ---------- Feature 1: Daily Audio Digest ---------- # def generate_audio_digest(topic): # dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10 # summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"] # audio_path = "digest.wav" # tts.tts_to_file(text=summary, file_path=audio_path) # return summary, audio_path # # ---------- Feature 2: Interactive Story Generator ---------- # story_cache = {} # # More vivid genre-specific prompts # genre_templates = { # "fantasy": "In a land of dragons and forgotten magic, a tale begins. ", # "sci-fi": "In a distant galaxy, governed by AI and cosmic laws, a new story unfolds. ", # "thriller": "It started on a stormy night, when a single knock on the door changed everything. ", # "romance": "They locked eyes for the first time in a quiet bookstore. ", # "horror": "The clock struck midnight, and something moved in the shadows. ", # "myth": "Long before time was time, gods and mortals shared the same sky. ", # "comedy": "There was once a chicken who wanted to cross a space highway... " # } # # Random creative twist options # twist_prompts = [ # "But little did they know, everything was about to change.", # "Suddenly, a mysterious voice echoed in the air.", # "Out of nowhere, a glowing symbol appeared.", # "But fate had other plans.", # "And just like that, the rules of the world shifted." # ] # def generate_story(genre, choice): # genre = genre.lower() # base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}. ") # # If it's a new story # if genre not in story_cache: # story_cache[genre] = base_prompt # # Add user decision and twist # if choice: # twist = random.choice(twist_prompts) # story_cache[genre] += f"\nThe user chose: '{choice}'. {twist} " # # Generate new content # generated = story_gen(story_cache[genre])[0]['generated_text'] # # Update cache for continuity # story_cache[genre] = generated # # Audio output # story_audio_path = "story.wav" # tts.tts_to_file(text=generated, file_path=story_audio_path) # return generated, story_audio_path # # ---------- Gradio UI ---------- # digest_ui = gr.Interface( # fn=generate_audio_digest, # inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, productivity"), # outputs=[gr.Text(label="Summary"), gr.Audio(label="Audio Digest", type="filepath")], # title="🎧 KukuBuddy: Daily Audio Digest" # ) # story_ui = gr.Interface( # fn=generate_story, # inputs=[ # gr.Textbox(label="Genre", placeholder="e.g. sci-fi, myth, thriller"), # gr.Textbox(label="Your last choice", placeholder="e.g. Enter the castle") # ], # outputs=[gr.Text(label="Next Scene"), gr.Audio(label="Narration", type="filepath")], # title="📖 KukuBuddy: Interactive Story" # ) # app = gr.TabbedInterface([digest_ui, story_ui], tab_names=["📌 Daily Digest", "🧠 Interactive Story"]) # if __name__ == "__main__": # app.launch() # import random # import gradio as gr # from transformers import pipeline # from TTS.api import TTS # # Small & memory-efficient models # summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # story_gen = pipeline("text2text-generation", model="google/flan-t5-small") # tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False) # # ---------- Feature 1: Daily Audio Digest ---------- # def generate_audio_digest(topic): # dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10 # summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"] # audio_path = "digest.wav" # tts.tts_to_file(text=summary, file_path=audio_path) # return summary, audio_path, audio_path # return twice for play and download # # ---------- Feature 2: Interactive Story Generator ---------- # story_cache = {} # # More vivid genre-specific prompts # genre_templates = { # "fantasy": "In a land of dragons and forgotten magic, a tale begins. ", # "sci-fi": "In a distant galaxy, governed by AI and cosmic laws, a new story unfolds. ", # "thriller": "It started on a stormy night, when a single knock on the door changed everything. ", # "romance": "They locked eyes for the first time in a quiet bookstore. ", # "horror": "The clock struck midnight, and something moved in the shadows. ", # "myth": "Long before time was time, gods and mortals shared the same sky. ", # "comedy": "There was once a chicken who wanted to cross a space highway... " # } # # Random creative twist options # twist_prompts = [ # "But little did they know, everything was about to change.", # "Suddenly, a mysterious voice echoed in the air.", # "Out of nowhere, a glowing symbol appeared.", # "But fate had other plans.", # "And just like that, the rules of the world shifted." # ] # def generate_story(genre, choice): # genre = genre.lower() # base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}. ") # # If it's a new story # if genre not in story_cache: # story_cache[genre] = base_prompt # # Add user decision and twist # if choice: # twist = random.choice(twist_prompts) # story_cache[genre] += f"\nThe user chose: '{choice}'. {twist} " # # Generate new content # generated = story_gen(story_cache[genre])[0]['generated_text'] # # Update cache for continuity # story_cache[genre] = generated # # Audio output # story_audio_path = "story.wav" # tts.tts_to_file(text=generated, file_path=story_audio_path) # return generated, story_audio_path, story_audio_path # return twice for play and download # # ---------- Gradio UI ---------- # digest_ui = gr.Interface( # fn=generate_audio_digest, # inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, productivity"), # outputs=[ # gr.Text(label="Summary"), # gr.Audio(label="🔊 Audio Digest", type="filepath"), # gr.File(label="⬇️ Download Audio File") # ], # title="🎧 KukuBuddy: Daily Audio Digest" # ) # story_ui = gr.Interface( # fn=generate_story, # inputs=[ # gr.Textbox(label="Genre", placeholder="e.g. sci-fi, myth, thriller"), # gr.Textbox(label="Your last choice", placeholder="e.g. Enter the castle") # ], # outputs=[ # gr.Text(label="📖 Next Scene"), # gr.Audio(label="🔊 Narration", type="filepath"), # gr.File(label="⬇️ Download Narration") # ], # title="📖 KukuBuddy: Interactive Story" # ) # app = gr.TabbedInterface( # [digest_ui, story_ui], # tab_names=["📌 Daily Digest", "🧠 Interactive Story"] # ) # if __name__ == "__main__": # app.launch() # kukubuddy_ai_light.py # import random # import gradio as gr # from transformers import pipeline # from TTS.api import TTS # # Small & memory-efficient models # summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # story_gen = pipeline("text2text-generation", model="google/flan-t5-small") # tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False) # # ---------- Feature 1: Daily Audio Digest ---------- # def generate_audio_digest(topic): # dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10 # summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"] # audio_path = "digest.wav" # tts.tts_to_file(text=summary, file_path=audio_path) # return summary, audio_path, audio_path # # ---------- Feature 2: Interactive Story Generator ---------- # # Genre-specific openers # genre_templates = { # "fantasy": "In a land of dragons and forgotten magic, a tale begins.", # "sci-fi": "In a distant galaxy, governed by AI and cosmic laws, a new story unfolds.", # "thriller": "It started on a stormy night, when a single knock on the door changed everything.", # "romance": "They locked eyes for the first time in a quiet bookstore.", # "horror": "The clock struck midnight, and something moved in the shadows.", # "myth": "Long before time was time, gods and mortals shared the same sky.", # "comedy": "There was once a chicken who wanted to cross a space highway..." # } # # Optional creative twists for inspiration (no longer injected into prompt text) # twist_prompts = [ # "But little did they know, everything was about to change.", # "Suddenly, a mysterious voice echoed in the air.", # "Out of nowhere, a glowing symbol appeared.", # "But fate had other plans.", # "And just like that, the rules of the world shifted." # ] # def generate_story(genre, choice): # genre = genre.lower() # base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}.") # prompt = base_prompt # if choice: # twist = random.choice(twist_prompts) # prompt += f" The character decided to '{choice}'. {twist}" # generated = story_gen(prompt)[0]['generated_text'] # story_audio_path = "story.wav" # tts.tts_to_file(text=generated, file_path=story_audio_path) # return generated, story_audio_path, story_audio_path # # ---------- Gradio UI ---------- # digest_ui = gr.Interface( # fn=generate_audio_digest, # inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, productivity"), # outputs=[ # gr.Textbox(label="Summary", lines=5), # gr.Audio(label="🔊 Audio Digest", type="filepath"), # gr.File(label="⬇️ Download Audio File") # ], # title="🎧 KukuBuddy: Daily Audio Digest" # ) # story_ui = gr.Interface( # fn=generate_story, # inputs=[ # gr.Textbox(label="Genre", placeholder="e.g. sci-fi, myth, thriller"), # gr.Textbox(label="Your last choice", placeholder="e.g. Enter the castle") # ], # outputs=[ # gr.Textbox(label="📖 Next Scene", lines=5), # gr.Audio(label="🔊 Narration", type="filepath"), # gr.File(label="⬇️ Download Narration") # ], # title="📖 KukuBuddy: Interactive Story" # ) # app = gr.TabbedInterface( # [digest_ui, story_ui], # tab_names=["📌 Daily Digest", "🧠 Interactive Story"] # ) # if __name__ == "__main__": # app.launch() # import random # import gradio as gr # from transformers import pipeline # from TTS.api import TTS # # --------------- Lightweight Models --------------- # summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # story_gen = pipeline("text-generation", model="datificate/gpt2-small-story", max_length=250, pad_token_id=50256) # tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False) # # --------------- Feature 1: Daily Audio Digest --------------- # def generate_audio_digest(topic): # dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10 # summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"] # audio_path = "digest.wav" # tts.tts_to_file(text=summary, file_path=audio_path) # return summary, audio_path, audio_path # # --------------- Feature 2: Interactive Story Generator --------------- # story_cache = {} # # Genre-specific openers # genre_templates = { # "fantasy": "In a land of dragons and forgotten magic, a tale begins.", # "sci-fi": "In a distant galaxy governed by AI and cosmic laws, a new story unfolds.", # "thriller": "It started on a stormy night, when a knock on the door changed everything.", # "romance": "They locked eyes for the first time in a quiet bookstore.", # "horror": "The clock struck midnight, and something moved in the shadows.", # "myth": "Long before time began, gods and mortals shared the same sky.", # "comedy": "There was once a chicken who wanted to cross a space highway..." # } # def generate_story(genre, choice): # genre = genre.lower() # base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}.") # prompt = base_prompt # if choice: # prompt += f" The character decided to '{choice}'." # # GPT-style continuation # prompt += " What happened next was" # generated = story_gen(prompt, do_sample=True, top_p=0.92, temperature=0.9)[0]['generated_text'] # # Extract only the new scene, not the input prompt # next_scene = generated[len(prompt):].strip() # story_audio_path = "story.wav" # tts.tts_to_file(text=next_scene, file_path=story_audio_path) # return next_scene, story_audio_path, story_audio_path # # --------------- Gradio UI --------------- # digest_ui = gr.Interface( # fn=generate_audio_digest, # inputs=gr.Textbox(label="🎯 Enter your topic of interest", placeholder="e.g. motivation, productivity", lines=2), # outputs=[ # gr.Textbox(label="📝 Summary", lines=4), # gr.Audio(label="🎧 Audio Digest", type="filepath"), # gr.File(label="⬇️ Download Audio") # ], # title="🎧 KukuBuddy: Daily Audio Digest" # ) # story_ui = gr.Interface( # fn=generate_story, # inputs=[ # gr.Textbox(label="📚 Genre", placeholder="e.g. sci-fi, myth, thriller", lines=1), # gr.Textbox(label="🎮 Your last choice", placeholder="e.g. Enter the castle", lines=2) # ], # outputs=[ # gr.Textbox(label="📝 Next Scene", lines=4), # gr.Audio(label="🎧 Narration", type="filepath"), # gr.File(label="⬇️ Download Audio") # ], # title="📖 KukuBuddy: Interactive Story" # ) # app = gr.TabbedInterface([digest_ui, story_ui], tab_names=["📌 Daily Digest", "🧠 Interactive Story"]) # if __name__ == "__main__": # app.launch() # import random # import gradio as gr # from transformers import pipeline # from TTS.api import TTS # # --------------- Lightweight Models --------------- # summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # story_gen = pipeline("text-generation", model="mrm8488/GPT-2-finetuned-fiction", max_length=250, pad_token_id=50256) # tts = TTS(model_name="tts_models/en/ljspeech/glow-tts", progress_bar=False, gpu=False) # # --------------- Feature 1: Daily Audio Digest --------------- # def generate_audio_digest(topic): # dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10 # summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"] # audio_path = "digest.wav" # tts.tts_to_file(text=summary, file_path=audio_path) # return summary, audio_path, audio_path # # --------------- Feature 2: Interactive Story Generator --------------- # genre_templates = { # "fantasy": "In a land of dragons and forgotten magic, a tale begins.", # "sci-fi": "In a distant galaxy governed by AI and cosmic laws, a new story unfolds.", # "thriller": "It started on a stormy night, when a knock on the door changed everything.", # "romance": "They locked eyes for the first time in a quiet bookstore.", # "horror": "The clock struck midnight, and something moved in the shadows.", # "myth": "Long before time began, gods and mortals shared the same sky.", # "comedy": "There was once a chicken who wanted to cross a space highway..." # } # def generate_story(genre, choice): # genre = genre.lower() # base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}.") # prompt = base_prompt # if choice: # prompt += f" The character decided to '{choice}'." # prompt += " What happened next was" # generated = story_gen(prompt, do_sample=True, top_p=0.92, temperature=0.9)[0]['generated_text'] # next_scene = generated[len(prompt):].strip() # story_audio_path = "story.wav" # tts.tts_to_file(text=next_scene, file_path=story_audio_path) # return next_scene, story_audio_path, story_audio_path # # --------------- Gradio UI --------------- # digest_ui = gr.Interface( # fn=generate_audio_digest, # inputs=gr.Textbox(label="🎯 Enter your topic of interest", placeholder="e.g. motivation, productivity", lines=2), # outputs=[ # gr.Textbox(label="📝 Summary", lines=4), # gr.Audio(label="🎧 Audio Digest", type="filepath"), # gr.File(label="⬇️ Download Audio") # ], # title="🎧 KukuBuddy: Daily Audio Digest" # ) # story_ui = gr.Interface( # fn=generate_story, # inputs=[ # gr.Textbox(label="📚 Genre", placeholder="e.g. sci-fi, myth, thriller", lines=1), # gr.Textbox(label="🎮 Your last choice", placeholder="e.g. Enter the castle", lines=2) # ], # outputs=[ # gr.Textbox(label="📝 Next Scene", lines=4), # gr.Audio(label="🎧 Narration", type="filepath"), # gr.File(label="⬇️ Download Audio") # ], # title="📖 KukuBuddy: Interactive Story" # ) # app = gr.TabbedInterface([digest_ui, story_ui], tab_names=["📌 Daily Digest", "🧠 Interactive Story"]) # if __name__ == "__main__": # app.launch() import random import gradio as gr from transformers import pipeline, set_seed from TTS.api import TTS # --------------- Lightweight Models --------------- summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") story_gen = pipeline("text-generation", model="aspis/gpt2-genre-story-generation", max_length=250, pad_token_id=50256) set_seed(42) tts = TTS(model_name="tts_models/en/ljspeech/glow-tts", progress_bar=False, gpu=False) # --------------- Feature 1: Daily Audio Digest --------------- def generate_audio_digest(topic): dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10 summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"] audio_path = "digest.wav" tts.tts_to_file(text=summary, file_path=audio_path) return summary, audio_path, audio_path # --------------- Feature 2: Interactive Story Generator --------------- # Genre-specific openers to guide the style of the story genre_templates = { "fantasy": "In a land of dragons and forgotten magic, a tale begins.", "sci-fi": "In a distant galaxy governed by AI and cosmic laws, a new story unfolds.", "thriller": "It started on a stormy night, when a knock on the door changed everything.", "romance": "They locked eyes for the first time in a quiet bookstore.", "horror": "The clock struck midnight, and something moved in the shadows.", "myth": "Long before time began, gods and mortals shared the same sky.", "comedy": "There was once a chicken who wanted to cross a space highway..." } def generate_story(genre, choice): genre = genre.lower() base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}.") # Build a more detailed prompt using the user's choice. prompt = base_prompt if choice: prompt += f" The protagonist made a bold decision: '{choice}'." # Add clear instructions to generate a coherent narrative. prompt += " Continue the story in a creative and engaging way. Develop the characters and emotions naturally." generated = story_gen(prompt, do_sample=True, top_p=0.9, temperature=0.85)[0]['generated_text'] # Extract only the generated continuation. next_scene = generated[len(prompt):].strip() story_audio_path = "story.wav" tts.tts_to_file(text=next_scene, file_path=story_audio_path) return next_scene, story_audio_path, story_audio_path # --------------- Gradio UI --------------- digest_ui = gr.Interface( fn=generate_audio_digest, inputs=gr.Textbox(label="🎯 Enter your topic of interest", placeholder="e.g. motivation, productivity", lines=2), outputs=[ gr.Textbox(label="📝 Summary", lines=4), gr.Audio(label="🎧 Audio Digest", type="filepath"), gr.File(label="⬇️ Download Audio") ], title="🎧 KukuBuddy: Daily Audio Digest" ) story_ui = gr.Interface( fn=generate_story, inputs=[ gr.Textbox(label="📚 Genre", placeholder="e.g. sci-fi, myth, thriller, romance", lines=1), gr.Textbox(label="🎮 Your last choice", placeholder="e.g. Enter the castle", lines=2) ], outputs=[ gr.Textbox(label="📝 Next Scene", lines=4), gr.Audio(label="🎧 Narration", type="filepath"), gr.File(label="⬇️ Download Audio") ], title="📖 KukuBuddy: Interactive Story" ) app = gr.TabbedInterface([digest_ui, story_ui], tab_names=["📌 Daily Digest", "🧠 Interactive Story"]) if __name__ == "__main__": app.launch()