Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -289,15 +289,102 @@
|
|
289 |
# if __name__ == "__main__":
|
290 |
# app.launch()
|
291 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
import random
|
293 |
import gradio as gr
|
294 |
from transformers import pipeline
|
295 |
from TTS.api import TTS
|
296 |
|
297 |
# --------------- Lightweight Models ---------------
|
298 |
-
summarizer = pipeline("summarization", model="
|
299 |
-
story_gen = pipeline("text-generation", model="
|
300 |
-
tts = TTS(model_name="tts_models/en/ljspeech/
|
301 |
|
302 |
# --------------- Feature 1: Daily Audio Digest ---------------
|
303 |
def generate_audio_digest(topic):
|
@@ -310,9 +397,6 @@ def generate_audio_digest(topic):
|
|
310 |
return summary, audio_path, audio_path
|
311 |
|
312 |
# --------------- Feature 2: Interactive Story Generator ---------------
|
313 |
-
story_cache = {}
|
314 |
-
|
315 |
-
# Genre-specific openers
|
316 |
genre_templates = {
|
317 |
"fantasy": "In a land of dragons and forgotten magic, a tale begins.",
|
318 |
"sci-fi": "In a distant galaxy governed by AI and cosmic laws, a new story unfolds.",
|
@@ -331,12 +415,9 @@ def generate_story(genre, choice):
|
|
331 |
if choice:
|
332 |
prompt += f" The character decided to '{choice}'."
|
333 |
|
334 |
-
# GPT-style continuation
|
335 |
prompt += " What happened next was"
|
336 |
|
337 |
generated = story_gen(prompt, do_sample=True, top_p=0.92, temperature=0.9)[0]['generated_text']
|
338 |
-
|
339 |
-
# Extract only the new scene, not the input prompt
|
340 |
next_scene = generated[len(prompt):].strip()
|
341 |
|
342 |
story_audio_path = "story.wav"
|
@@ -377,3 +458,4 @@ if __name__ == "__main__":
|
|
377 |
app.launch()
|
378 |
|
379 |
|
|
|
|
289 |
# if __name__ == "__main__":
|
290 |
# app.launch()
|
291 |
|
292 |
+
# import random
|
293 |
+
# import gradio as gr
|
294 |
+
# from transformers import pipeline
|
295 |
+
# from TTS.api import TTS
|
296 |
+
|
297 |
+
# # --------------- Lightweight Models ---------------
|
298 |
+
# summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
|
299 |
+
# story_gen = pipeline("text-generation", model="datificate/gpt2-small-story", max_length=250, pad_token_id=50256)
|
300 |
+
# tts = TTS(model_name="tts_models/en/ljspeech/tacotron2-DDC", progress_bar=False, gpu=False)
|
301 |
+
|
302 |
+
# # --------------- Feature 1: Daily Audio Digest ---------------
|
303 |
+
# def generate_audio_digest(topic):
|
304 |
+
# dummy_text = f"This is a sample Kuku FM podcast about {topic}. " * 10
|
305 |
+
# summary = summarizer(dummy_text, max_length=300, min_length=30, do_sample=False)[0]["summary_text"]
|
306 |
+
|
307 |
+
# audio_path = "digest.wav"
|
308 |
+
# tts.tts_to_file(text=summary, file_path=audio_path)
|
309 |
+
|
310 |
+
# return summary, audio_path, audio_path
|
311 |
+
|
312 |
+
# # --------------- Feature 2: Interactive Story Generator ---------------
|
313 |
+
# story_cache = {}
|
314 |
+
|
315 |
+
# # Genre-specific openers
|
316 |
+
# genre_templates = {
|
317 |
+
# "fantasy": "In a land of dragons and forgotten magic, a tale begins.",
|
318 |
+
# "sci-fi": "In a distant galaxy governed by AI and cosmic laws, a new story unfolds.",
|
319 |
+
# "thriller": "It started on a stormy night, when a knock on the door changed everything.",
|
320 |
+
# "romance": "They locked eyes for the first time in a quiet bookstore.",
|
321 |
+
# "horror": "The clock struck midnight, and something moved in the shadows.",
|
322 |
+
# "myth": "Long before time began, gods and mortals shared the same sky.",
|
323 |
+
# "comedy": "There was once a chicken who wanted to cross a space highway..."
|
324 |
+
# }
|
325 |
+
|
326 |
+
# def generate_story(genre, choice):
|
327 |
+
# genre = genre.lower()
|
328 |
+
# base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}.")
|
329 |
+
|
330 |
+
# prompt = base_prompt
|
331 |
+
# if choice:
|
332 |
+
# prompt += f" The character decided to '{choice}'."
|
333 |
+
|
334 |
+
# # GPT-style continuation
|
335 |
+
# prompt += " What happened next was"
|
336 |
+
|
337 |
+
# generated = story_gen(prompt, do_sample=True, top_p=0.92, temperature=0.9)[0]['generated_text']
|
338 |
+
|
339 |
+
# # Extract only the new scene, not the input prompt
|
340 |
+
# next_scene = generated[len(prompt):].strip()
|
341 |
+
|
342 |
+
# story_audio_path = "story.wav"
|
343 |
+
# tts.tts_to_file(text=next_scene, file_path=story_audio_path)
|
344 |
+
|
345 |
+
# return next_scene, story_audio_path, story_audio_path
|
346 |
+
|
347 |
+
# # --------------- Gradio UI ---------------
|
348 |
+
|
349 |
+
# digest_ui = gr.Interface(
|
350 |
+
# fn=generate_audio_digest,
|
351 |
+
# inputs=gr.Textbox(label="🎯 Enter your topic of interest", placeholder="e.g. motivation, productivity", lines=2),
|
352 |
+
# outputs=[
|
353 |
+
# gr.Textbox(label="📝 Summary", lines=4),
|
354 |
+
# gr.Audio(label="🎧 Audio Digest", type="filepath"),
|
355 |
+
# gr.File(label="⬇️ Download Audio")
|
356 |
+
# ],
|
357 |
+
# title="🎧 KukuBuddy: Daily Audio Digest"
|
358 |
+
# )
|
359 |
+
|
360 |
+
# story_ui = gr.Interface(
|
361 |
+
# fn=generate_story,
|
362 |
+
# inputs=[
|
363 |
+
# gr.Textbox(label="📚 Genre", placeholder="e.g. sci-fi, myth, thriller", lines=1),
|
364 |
+
# gr.Textbox(label="🎮 Your last choice", placeholder="e.g. Enter the castle", lines=2)
|
365 |
+
# ],
|
366 |
+
# outputs=[
|
367 |
+
# gr.Textbox(label="📝 Next Scene", lines=4),
|
368 |
+
# gr.Audio(label="🎧 Narration", type="filepath"),
|
369 |
+
# gr.File(label="⬇️ Download Audio")
|
370 |
+
# ],
|
371 |
+
# title="📖 KukuBuddy: Interactive Story"
|
372 |
+
# )
|
373 |
+
|
374 |
+
# app = gr.TabbedInterface([digest_ui, story_ui], tab_names=["📌 Daily Digest", "🧠 Interactive Story"])
|
375 |
+
|
376 |
+
# if __name__ == "__main__":
|
377 |
+
# app.launch()
|
378 |
+
|
379 |
import random
|
380 |
import gradio as gr
|
381 |
from transformers import pipeline
|
382 |
from TTS.api import TTS
|
383 |
|
384 |
# --------------- Lightweight Models ---------------
|
385 |
+
summarizer = pipeline("summarization", model="knkarthick/MEETING_SUMMARY")
|
386 |
+
story_gen = pipeline("text-generation", model="distilgpt2", max_length=250, pad_token_id=50256)
|
387 |
+
tts = TTS(model_name="tts_models/en/ljspeech/glow-tts", progress_bar=False, gpu=False)
|
388 |
|
389 |
# --------------- Feature 1: Daily Audio Digest ---------------
|
390 |
def generate_audio_digest(topic):
|
|
|
397 |
return summary, audio_path, audio_path
|
398 |
|
399 |
# --------------- Feature 2: Interactive Story Generator ---------------
|
|
|
|
|
|
|
400 |
genre_templates = {
|
401 |
"fantasy": "In a land of dragons and forgotten magic, a tale begins.",
|
402 |
"sci-fi": "In a distant galaxy governed by AI and cosmic laws, a new story unfolds.",
|
|
|
415 |
if choice:
|
416 |
prompt += f" The character decided to '{choice}'."
|
417 |
|
|
|
418 |
prompt += " What happened next was"
|
419 |
|
420 |
generated = story_gen(prompt, do_sample=True, top_p=0.92, temperature=0.9)[0]['generated_text']
|
|
|
|
|
421 |
next_scene = generated[len(prompt):].strip()
|
422 |
|
423 |
story_audio_path = "story.wav"
|
|
|
458 |
app.launch()
|
459 |
|
460 |
|
461 |
+
|