Bhaskar2611 commited on
Commit
55d6eec
·
verified ·
1 Parent(s): b5519c0

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # kukubuddy_ai.py
2
+
3
+ import gradio as gr
4
+ from transformers import pipeline
5
+ from TTS.api import TTS
6
+
7
+ # Load Hugging Face pipelines
8
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
9
+ story_gen = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", max_length=300)
10
+ tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
11
+
12
+ # ---------- Feature 1: Daily Audio Digest ----------
13
+ def generate_audio_digest(topic):
14
+ # Simulate a long dummy content (replace with real data from KukuFM backend)
15
+ dummy_text = f"This is a sample podcast on {topic}. " * 20
16
+ summary = summarizer(dummy_text, max_length=120, min_length=30, do_sample=False)[0]["summary_text"]
17
+
18
+ # Convert summary to speech
19
+ audio_path = "digest.wav"
20
+ tts.tts_to_file(text=summary, file_path=audio_path)
21
+
22
+ return summary, audio_path
23
+
24
+ # ---------- Feature 2: Interactive Story Generator ----------
25
+ story_cache = {}
26
+
27
+ def generate_story(genre, choice):
28
+ base_prompt = f"Start a {genre} story. "
29
+
30
+ if genre not in story_cache:
31
+ story_cache[genre] = base_prompt
32
+
33
+ if choice:
34
+ story_cache[genre] += f"\nUser chose: {choice}. Then, "
35
+
36
+ generated = story_gen(story_cache[genre])[0]['generated_text']
37
+ story_cache[genre] = generated # Save for next turn
38
+
39
+ # Convert story to audio
40
+ story_audio_path = "story.wav"
41
+ tts.tts_to_file(text=generated, file_path=story_audio_path)
42
+
43
+ return generated, story_audio_path
44
+
45
+ # ---------- Gradio Interface ----------
46
+
47
+ # Daily Digest UI
48
+ digest_ui = gr.Interface(
49
+ fn=generate_audio_digest,
50
+ inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, startups, mental health"),
51
+ outputs=[
52
+ gr.Text(label="AI-Generated Summary"),
53
+ gr.Audio(label="Listen to Your Digest", type="filepath")
54
+ ],
55
+ title="🎧 KukuBuddy: Personalized Daily Audio Digest"
56
+ )
57
+
58
+ # Story Generator UI
59
+ story_ui = gr.Interface(
60
+ fn=generate_story,
61
+ inputs=[
62
+ gr.Textbox(label="Choose a genre", placeholder="e.g. sci-fi, romance, horror"),
63
+ gr.Textbox(label="Your last choice (optional)", placeholder="e.g. Enter the cave")
64
+ ],
65
+ outputs=[
66
+ gr.Text(label="Next part of the story"),
67
+ gr.Audio(label="Narration", type="filepath")
68
+ ],
69
+ title="📖 KukuBuddy: Interactive Audio Story Generator"
70
+ )
71
+
72
+ # Tabbed app
73
+ app = gr.TabbedInterface(
74
+ interface_list=[digest_ui, story_ui],
75
+ tab_names=["📌 Daily Audio Digest", "🧠 Interactive Story"]
76
+ )
77
+
78
+ # Run the app
79
+ if __name__ == "__main__":
80
+ app.launch()