Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,22 +22,54 @@ def generate_audio_digest(topic):
|
|
22 |
# ---------- Feature 2: Interactive Story Generator ----------
|
23 |
story_cache = {}
|
24 |
|
25 |
-
def generate_story(genre, choice):
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
# ---------- Gradio UI ----------
|
43 |
|
|
|
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 |
+
def generate_story(genre, scene_input):
|
43 |
+
# Define genre-specific styles
|
44 |
+
genre_styles = {
|
45 |
+
"action": "Include fast-paced sequences, intense confrontations, and physical conflict. Add thrilling suspense and end with a dramatic cliffhanger.",
|
46 |
+
"romance": "Highlight emotional tension, subtle gestures, and deep connection between characters. Use heartfelt dialogue and end with a tender or surprising moment.",
|
47 |
+
"comedy": "Use witty dialogue, humorous misunderstandings, and light-hearted narration. Keep the tone playful and funny.",
|
48 |
+
"thriller": "Add psychological tension, mysterious clues, and an unsettling atmosphere. End with a chilling or puzzling moment.",
|
49 |
+
"fantasy": "Include magical elements, otherworldly creatures, and vivid scenery. Use epic tone and mystical storytelling.",
|
50 |
+
"horror": "Use eerie descriptions, building dread, and jump-scare moments. End on a terrifying note.",
|
51 |
+
"sci-fi": "Incorporate futuristic tech, space travel, or AI. Build an immersive setting and challenge the reader’s imagination.",
|
52 |
+
"drama": "Emphasize emotional depth, personal conflict, and realistic dialogue. Add introspective moments.",
|
53 |
+
}
|
54 |
+
|
55 |
+
# Fallback style if genre not found
|
56 |
+
style = genre_styles.get(genre.lower(), "Write in an immersive and engaging tone relevant to the genre.")
|
57 |
+
|
58 |
+
# Build the prompt
|
59 |
+
prompt = (
|
60 |
+
f"[INST] You are a brilliant storyteller. Write a vivid and immersive scene in a {genre} story. "
|
61 |
+
f"The scene starts like this: {scene_input}. {style} [/INST]"
|
62 |
+
)
|
63 |
+
|
64 |
+
# Generate the story using your pipeline (story_gen)
|
65 |
+
response = story_gen(prompt, max_length=300, do_sample=True, temperature=0.8, top_p=0.95)[0]['generated_text']
|
66 |
+
|
67 |
+
# Convert to speech
|
68 |
+
story_audio_path = "story.wav"
|
69 |
+
tts.tts_to_file(text=response, file_path=story_audio_path)
|
70 |
+
|
71 |
+
return response, story_audio_path
|
72 |
+
|
73 |
|
74 |
# ---------- Gradio UI ----------
|
75 |
|