# kukubuddy_ai.py import gradio as gr from transformers import pipeline from TTS.api import TTS # Load Hugging Face pipelines summarizer = pipeline("summarization", model="facebook/bart-large-cnn") story_gen = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", max_length=300) 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): # Simulate a long dummy content (replace with real data from KukuFM backend) dummy_text = f"This is a sample podcast on {topic}. " * 20 summary = summarizer(dummy_text, max_length=120, min_length=30, do_sample=False)[0]["summary_text"] # Convert summary to speech 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 {genre} story. " if genre not in story_cache: story_cache[genre] = base_prompt if choice: story_cache[genre] += f"\nUser chose: {choice}. Then, " generated = story_gen(story_cache[genre])[0]['generated_text'] story_cache[genre] = generated # Save for next turn # Convert story to audio story_audio_path = "story.wav" tts.tts_to_file(text=generated, file_path=story_audio_path) return generated, story_audio_path # ---------- Gradio Interface ---------- # Daily Digest UI digest_ui = gr.Interface( fn=generate_audio_digest, inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, startups, mental health"), outputs=[ gr.Text(label="AI-Generated Summary"), gr.Audio(label="Listen to Your Digest", type="filepath") ], title="🎧 KukuBuddy: Personalized Daily Audio Digest" ) # Story Generator UI story_ui = gr.Interface( fn=generate_story, inputs=[ gr.Textbox(label="Choose a genre", placeholder="e.g. sci-fi, romance, horror"), gr.Textbox(label="Your last choice (optional)", placeholder="e.g. Enter the cave") ], outputs=[ gr.Text(label="Next part of the story"), gr.Audio(label="Narration", type="filepath") ], title="📖 KukuBuddy: Interactive Audio Story Generator" ) # Tabbed app app = gr.TabbedInterface( interface_list=[digest_ui, story_ui], tab_names=["📌 Daily Audio Digest", "🧠 Interactive Story"] ) # Run the app if __name__ == "__main__": app.launch()