Kuku_bot / app.py
Bhaskar2611's picture
Update app.py
80fdd14 verified
raw
history blame
2.22 kB
# kukubuddy_ai_light.py
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=100, 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
# ---------- 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()