Bhaskar2611 commited on
Commit
e1c1518
·
verified ·
1 Parent(s): af05401

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -9
app.py CHANGED
@@ -1,9 +1,8 @@
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")
@@ -22,24 +21,71 @@ def generate_audio_digest(topic):
22
  # ---------- Feature 2: Interactive Story Generator ----------
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
 
 
43
  # ---------- Gradio UI ----------
44
 
45
  digest_ui = gr.Interface(
 
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")
 
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. ",
45
+ "sci-fi": "In a distant galaxy, governed by AI and cosmic laws, a new story unfolds. ",
46
+ "thriller": "It started on a stormy night, when a single knock on the door changed everything. ",
47
+ "romance": "They locked eyes for the first time in a quiet bookstore. ",
48
+ "horror": "The clock struck midnight, and something moved in the shadows. ",
49
+ "myth": "Long before time was time, gods and mortals shared the same sky. ",
50
+ "comedy": "There was once a chicken who wanted to cross a space highway... "
51
+ }
52
+
53
+ # Random creative twist options
54
+ twist_prompts = [
55
+ "But little did they know, everything was about to change.",
56
+ "Suddenly, a mysterious voice echoed in the air.",
57
+ "Out of nowhere, a glowing symbol appeared.",
58
+ "But fate had other plans.",
59
+ "And just like that, the rules of the world shifted."
60
+ ]
61
+
62
+ def generate_story(genre, choice):
63
+ genre = genre.lower()
64
+ base_prompt = genre_templates.get(genre, f"Begin a story in the genre: {genre}. ")
65
+
66
+ # If it's a new story
67
  if genre not in story_cache:
68
  story_cache[genre] = base_prompt
69
+
70
+ # Add user decision and twist
71
  if choice:
72
+ twist = random.choice(twist_prompts)
73
+ story_cache[genre] += f"\nThe user chose: '{choice}'. {twist} "
74
+
75
+ # Generate new content
76
  generated = story_gen(story_cache[genre])[0]['generated_text']
77
+
78
+ # Update cache for continuity
79
  story_cache[genre] = generated
80
+
81
+ # Audio output
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(