Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,19 @@
|
|
1 |
-
#
|
2 |
|
3 |
import gradio as gr
|
4 |
from transformers import pipeline
|
5 |
from TTS.api import TTS
|
6 |
|
7 |
-
#
|
8 |
-
summarizer = pipeline("summarization", model="
|
9 |
-
story_gen = pipeline("
|
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 |
-
|
15 |
-
|
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 |
|
@@ -25,56 +23,42 @@ def generate_audio_digest(topic):
|
|
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"
|
35 |
|
36 |
generated = story_gen(story_cache[genre])[0]['generated_text']
|
37 |
-
story_cache[genre] = generated
|
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
|
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,
|
51 |
-
outputs=[
|
52 |
-
|
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="
|
63 |
-
gr.Textbox(label="Your last choice
|
64 |
-
],
|
65 |
-
outputs=[
|
66 |
-
gr.Text(label="Next part of the story"),
|
67 |
-
gr.Audio(label="Narration", type="filepath")
|
68 |
],
|
69 |
-
|
|
|
70 |
)
|
71 |
|
72 |
-
|
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()
|
|
|
1 |
+
# kukubuddy_ai_light.py
|
2 |
|
3 |
import gradio as gr
|
4 |
from transformers import pipeline
|
5 |
from TTS.api import TTS
|
6 |
|
7 |
+
# Small & memory-efficient models
|
8 |
+
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
9 |
+
story_gen = pipeline("text2text-generation", model="google/flan-t5-small")
|
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 |
+
dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10
|
15 |
+
summary = summarizer(dummy_text, max_length=100, min_length=30, do_sample=False)[0]["summary_text"]
|
|
|
16 |
|
|
|
17 |
audio_path = "digest.wav"
|
18 |
tts.tts_to_file(text=summary, file_path=audio_path)
|
19 |
|
|
|
23 |
story_cache = {}
|
24 |
|
25 |
def generate_story(genre, choice):
|
26 |
+
base_prompt = f"Start a short {genre} story. "
|
27 |
|
28 |
if genre not in story_cache:
|
29 |
story_cache[genre] = base_prompt
|
30 |
|
31 |
if choice:
|
32 |
+
story_cache[genre] += f"User chose: {choice}. Then, "
|
33 |
|
34 |
generated = story_gen(story_cache[genre])[0]['generated_text']
|
35 |
+
story_cache[genre] = generated
|
36 |
|
|
|
37 |
story_audio_path = "story.wav"
|
38 |
tts.tts_to_file(text=generated, file_path=story_audio_path)
|
39 |
|
40 |
return generated, story_audio_path
|
41 |
|
42 |
+
# ---------- Gradio UI ----------
|
43 |
|
|
|
44 |
digest_ui = gr.Interface(
|
45 |
fn=generate_audio_digest,
|
46 |
+
inputs=gr.Textbox(label="Enter your topic of interest", placeholder="e.g. motivation, productivity"),
|
47 |
+
outputs=[gr.Text(label="Summary"), gr.Audio(label="Audio Digest", type="filepath")],
|
48 |
+
title="🎧 KukuBuddy: Daily Audio Digest"
|
|
|
|
|
|
|
49 |
)
|
50 |
|
|
|
51 |
story_ui = gr.Interface(
|
52 |
fn=generate_story,
|
53 |
inputs=[
|
54 |
+
gr.Textbox(label="Genre", placeholder="e.g. sci-fi, myth, thriller"),
|
55 |
+
gr.Textbox(label="Your last choice", placeholder="e.g. Enter the castle")
|
|
|
|
|
|
|
|
|
56 |
],
|
57 |
+
outputs=[gr.Text(label="Next Scene"), gr.Audio(label="Narration", type="filepath")],
|
58 |
+
title="📖 KukuBuddy: Interactive Story"
|
59 |
)
|
60 |
|
61 |
+
app = gr.TabbedInterface([digest_ui, story_ui], tab_names=["📌 Daily Digest", "🧠 Interactive Story"])
|
|
|
|
|
|
|
|
|
62 |
|
|
|
63 |
if __name__ == "__main__":
|
64 |
app.launch()
|