# 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 = {} # def generate_story(genre, choice): # base_prompt = f"Start a short {genre} story. " # if genre not in story_cache: # story_cache[genre] = base_prompt # if choice: # story_cache[genre] += f"User chose: {choice}. Then, " # generated = story_gen(story_cache[genre])[0]['generated_text'] # story_cache[genre] = generated # story_audio_path = "story.wav" # tts.tts_to_file(text=generated, file_path=story_audio_path) # return generated, story_audio_path # 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()