Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,102 @@
|
|
1 |
-
# kukubuddy_ai_light.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import random
|
3 |
import gradio as gr
|
4 |
from transformers import pipeline
|
5 |
from TTS.api import TTS
|
|
|
6 |
# Small & memory-efficient models
|
7 |
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
8 |
story_gen = pipeline("text2text-generation", model="google/flan-t5-small")
|
@@ -16,29 +110,11 @@ def generate_audio_digest(topic):
|
|
16 |
audio_path = "digest.wav"
|
17 |
tts.tts_to_file(text=summary, file_path=audio_path)
|
18 |
|
19 |
-
return summary, audio_path
|
20 |
|
21 |
# ---------- Feature 2: Interactive Story Generator ----------
|
22 |
story_cache = {}
|
23 |
|
24 |
-
# def generate_story(genre, choice):
|
25 |
-
# base_prompt = f"Start a short {genre} story. "
|
26 |
-
|
27 |
-
# if genre not in story_cache:
|
28 |
-
# story_cache[genre] = base_prompt
|
29 |
-
|
30 |
-
# if choice:
|
31 |
-
# story_cache[genre] += f"User chose: {choice}. Then, "
|
32 |
-
|
33 |
-
# generated = story_gen(story_cache[genre])[0]['generated_text']
|
34 |
-
# story_cache[genre] = generated
|
35 |
-
|
36 |
-
# story_audio_path = "story.wav"
|
37 |
-
# tts.tts_to_file(text=generated, file_path=story_audio_path)
|
38 |
-
|
39 |
-
# return generated, story_audio_path
|
40 |
-
|
41 |
-
|
42 |
# More vivid genre-specific prompts
|
43 |
genre_templates = {
|
44 |
"fantasy": "In a land of dragons and forgotten magic, a tale begins. ",
|
@@ -82,16 +158,18 @@ def generate_story(genre, choice):
|
|
82 |
story_audio_path = "story.wav"
|
83 |
tts.tts_to_file(text=generated, file_path=story_audio_path)
|
84 |
|
85 |
-
return generated, story_audio_path
|
86 |
-
|
87 |
-
|
88 |
|
89 |
# ---------- Gradio UI ----------
|
90 |
|
91 |
digest_ui = gr.Interface(
|
92 |
fn=generate_audio_digest,
|
93 |
inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, productivity"),
|
94 |
-
outputs=[
|
|
|
|
|
|
|
|
|
95 |
title="🎧 KukuBuddy: Daily Audio Digest"
|
96 |
)
|
97 |
|
@@ -101,11 +179,18 @@ story_ui = gr.Interface(
|
|
101 |
gr.Textbox(label="Genre", placeholder="e.g. sci-fi, myth, thriller"),
|
102 |
gr.Textbox(label="Your last choice", placeholder="e.g. Enter the castle")
|
103 |
],
|
104 |
-
outputs=[
|
|
|
|
|
|
|
|
|
105 |
title="📖 KukuBuddy: Interactive Story"
|
106 |
)
|
107 |
|
108 |
-
app = gr.TabbedInterface(
|
|
|
|
|
|
|
109 |
|
110 |
if __name__ == "__main__":
|
111 |
app.launch()
|
|
|
1 |
+
# # kukubuddy_ai_light.py
|
2 |
+
# import random
|
3 |
+
# import gradio as gr
|
4 |
+
# from transformers import pipeline
|
5 |
+
# from TTS.api import TTS
|
6 |
+
# # Small & memory-efficient models
|
7 |
+
# summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
8 |
+
# story_gen = pipeline("text2text-generation", model="google/flan-t5-small")
|
9 |
+
# tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
|
10 |
+
|
11 |
+
# # ---------- Feature 1: Daily Audio Digest ----------
|
12 |
+
# def generate_audio_digest(topic):
|
13 |
+
# dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10
|
14 |
+
# summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"]
|
15 |
+
|
16 |
+
# audio_path = "digest.wav"
|
17 |
+
# tts.tts_to_file(text=summary, file_path=audio_path)
|
18 |
+
|
19 |
+
# return summary, audio_path
|
20 |
+
|
21 |
+
# # ---------- Feature 2: Interactive Story Generator ----------
|
22 |
+
# story_cache = {}
|
23 |
+
|
24 |
+
# # More vivid genre-specific prompts
|
25 |
+
# genre_templates = {
|
26 |
+
# "fantasy": "In a land of dragons and forgotten magic, a tale begins. ",
|
27 |
+
# "sci-fi": "In a distant galaxy, governed by AI and cosmic laws, a new story unfolds. ",
|
28 |
+
# "thriller": "It started on a stormy night, when a single knock on the door changed everything. ",
|
29 |
+
# "romance": "They locked eyes for the first time in a quiet bookstore. ",
|
30 |
+
# "horror": "The clock struck midnight, and something moved in the shadows. ",
|
31 |
+
# "myth": "Long before time was time, gods and mortals shared the same sky. ",
|
32 |
+
# "comedy": "There was once a chicken who wanted to cross a space highway... "
|
33 |
+
# }
|
34 |
+
|
35 |
+
# # Random creative twist options
|
36 |
+
# twist_prompts = [
|
37 |
+
# "But little did they know, everything was about to change.",
|
38 |
+
# "Suddenly, a mysterious voice echoed in the air.",
|
39 |
+
# "Out of nowhere, a glowing symbol appeared.",
|
40 |
+
# "But fate had other plans.",
|
41 |
+
# "And just like that, the rules of the world shifted."
|
42 |
+
# ]
|
43 |
+
|
44 |
+
# def generate_story(genre, choice):
|
45 |
+
# genre = genre.lower()
|
46 |
+
# base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}. ")
|
47 |
+
|
48 |
+
# # If it's a new story
|
49 |
+
# if genre not in story_cache:
|
50 |
+
# story_cache[genre] = base_prompt
|
51 |
+
|
52 |
+
# # Add user decision and twist
|
53 |
+
# if choice:
|
54 |
+
# twist = random.choice(twist_prompts)
|
55 |
+
# story_cache[genre] += f"\nThe user chose: '{choice}'. {twist} "
|
56 |
+
|
57 |
+
# # Generate new content
|
58 |
+
# generated = story_gen(story_cache[genre])[0]['generated_text']
|
59 |
+
|
60 |
+
# # Update cache for continuity
|
61 |
+
# story_cache[genre] = generated
|
62 |
+
|
63 |
+
# # Audio output
|
64 |
+
# story_audio_path = "story.wav"
|
65 |
+
# tts.tts_to_file(text=generated, file_path=story_audio_path)
|
66 |
+
|
67 |
+
# return generated, story_audio_path
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
# # ---------- Gradio UI ----------
|
72 |
+
|
73 |
+
# digest_ui = gr.Interface(
|
74 |
+
# fn=generate_audio_digest,
|
75 |
+
# inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, productivity"),
|
76 |
+
# outputs=[gr.Text(label="Summary"), gr.Audio(label="Audio Digest", type="filepath")],
|
77 |
+
# title="🎧 KukuBuddy: Daily Audio Digest"
|
78 |
+
# )
|
79 |
+
|
80 |
+
# story_ui = gr.Interface(
|
81 |
+
# fn=generate_story,
|
82 |
+
# inputs=[
|
83 |
+
# gr.Textbox(label="Genre", placeholder="e.g. sci-fi, myth, thriller"),
|
84 |
+
# gr.Textbox(label="Your last choice", placeholder="e.g. Enter the castle")
|
85 |
+
# ],
|
86 |
+
# outputs=[gr.Text(label="Next Scene"), gr.Audio(label="Narration", type="filepath")],
|
87 |
+
# title="📖 KukuBuddy: Interactive Story"
|
88 |
+
# )
|
89 |
+
|
90 |
+
# app = gr.TabbedInterface([digest_ui, story_ui], tab_names=["📌 Daily Digest", "🧠 Interactive Story"])
|
91 |
+
|
92 |
+
# if __name__ == "__main__":
|
93 |
+
# app.launch()
|
94 |
+
|
95 |
import random
|
96 |
import gradio as gr
|
97 |
from transformers import pipeline
|
98 |
from TTS.api import TTS
|
99 |
+
|
100 |
# Small & memory-efficient models
|
101 |
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
102 |
story_gen = pipeline("text2text-generation", model="google/flan-t5-small")
|
|
|
110 |
audio_path = "digest.wav"
|
111 |
tts.tts_to_file(text=summary, file_path=audio_path)
|
112 |
|
113 |
+
return summary, audio_path, audio_path # return twice for play and download
|
114 |
|
115 |
# ---------- Feature 2: Interactive Story Generator ----------
|
116 |
story_cache = {}
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
# More vivid genre-specific prompts
|
119 |
genre_templates = {
|
120 |
"fantasy": "In a land of dragons and forgotten magic, a tale begins. ",
|
|
|
158 |
story_audio_path = "story.wav"
|
159 |
tts.tts_to_file(text=generated, file_path=story_audio_path)
|
160 |
|
161 |
+
return generated, story_audio_path, story_audio_path # return twice for play and download
|
|
|
|
|
162 |
|
163 |
# ---------- Gradio UI ----------
|
164 |
|
165 |
digest_ui = gr.Interface(
|
166 |
fn=generate_audio_digest,
|
167 |
inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, productivity"),
|
168 |
+
outputs=[
|
169 |
+
gr.Text(label="Summary"),
|
170 |
+
gr.Audio(label="🔊 Audio Digest", type="filepath"),
|
171 |
+
gr.File(label="⬇️ Download Audio File")
|
172 |
+
],
|
173 |
title="🎧 KukuBuddy: Daily Audio Digest"
|
174 |
)
|
175 |
|
|
|
179 |
gr.Textbox(label="Genre", placeholder="e.g. sci-fi, myth, thriller"),
|
180 |
gr.Textbox(label="Your last choice", placeholder="e.g. Enter the castle")
|
181 |
],
|
182 |
+
outputs=[
|
183 |
+
gr.Text(label="📖 Next Scene"),
|
184 |
+
gr.Audio(label="🔊 Narration", type="filepath"),
|
185 |
+
gr.File(label="⬇️ Download Narration")
|
186 |
+
],
|
187 |
title="📖 KukuBuddy: Interactive Story"
|
188 |
)
|
189 |
|
190 |
+
app = gr.TabbedInterface(
|
191 |
+
[digest_ui, story_ui],
|
192 |
+
tab_names=["📌 Daily Digest", "🧠 Interactive Story"]
|
193 |
+
)
|
194 |
|
195 |
if __name__ == "__main__":
|
196 |
app.launch()
|