Spaces:
Running
Running
zach
commited on
Commit
·
96154e7
1
Parent(s):
7d79ca4
Add sample prompts to choose from as an alternative to writing a custom prompt for Claude
Browse files- src/app.py +22 -4
- src/sample_prompts.py +31 -0
src/app.py
CHANGED
|
@@ -21,6 +21,7 @@ import gradio as gr
|
|
| 21 |
# Local Application Imports
|
| 22 |
from src.config import logger
|
| 23 |
from src.integrations import generate_text_with_claude, text_to_speech_with_hume, text_to_speech_with_elevenlabs
|
|
|
|
| 24 |
from src.utils import truncate_text, validate_prompt_length
|
| 25 |
|
| 26 |
|
|
@@ -84,27 +85,44 @@ def build_gradio_interface() -> gr.Blocks:
|
|
| 84 |
)
|
| 85 |
|
| 86 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
prompt_input = gr.Textbox(
|
| 88 |
-
label="Enter your prompt",
|
| 89 |
-
placeholder="
|
| 90 |
lines=2,
|
| 91 |
)
|
| 92 |
|
| 93 |
with gr.Row():
|
| 94 |
generate_button = gr.Button("Generate")
|
| 95 |
|
|
|
|
| 96 |
with gr.Row():
|
| 97 |
output_text = gr.Textbox(
|
| 98 |
label="Generated Text",
|
| 99 |
interactive=False,
|
| 100 |
-
lines=
|
| 101 |
-
max_lines=
|
| 102 |
scale=2,
|
| 103 |
)
|
| 104 |
with gr.Column(scale=1):
|
| 105 |
hume_audio_output = gr.Audio(label="Hume TTS Audio", type="filepath")
|
| 106 |
elevenlabs_audio_output = gr.Audio(label="ElevenLabs TTS Audio", type="filepath")
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
# Attach the validation, text generation, and TTS processing logic
|
| 109 |
generate_button.click(
|
| 110 |
fn=process_prompt,
|
|
|
|
| 21 |
# Local Application Imports
|
| 22 |
from src.config import logger
|
| 23 |
from src.integrations import generate_text_with_claude, text_to_speech_with_hume, text_to_speech_with_elevenlabs
|
| 24 |
+
from src.sample_prompts import SAMPLE_PROMPTS
|
| 25 |
from src.utils import truncate_text, validate_prompt_length
|
| 26 |
|
| 27 |
|
|
|
|
| 85 |
)
|
| 86 |
|
| 87 |
with gr.Row():
|
| 88 |
+
# Dropdown for predefined prompts
|
| 89 |
+
sample_prompt_dropdown = gr.Dropdown(
|
| 90 |
+
choices=list(SAMPLE_PROMPTS.keys()),
|
| 91 |
+
label="Choose a Sample Prompt (or enter your own below)",
|
| 92 |
+
interactive=True
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
with gr.Row():
|
| 96 |
+
# Custom prompt input
|
| 97 |
prompt_input = gr.Textbox(
|
| 98 |
+
label="Enter your custom prompt",
|
| 99 |
+
placeholder="Or type your own custom prompt here...",
|
| 100 |
lines=2,
|
| 101 |
)
|
| 102 |
|
| 103 |
with gr.Row():
|
| 104 |
generate_button = gr.Button("Generate")
|
| 105 |
|
| 106 |
+
# Display the generated text and audio side by side
|
| 107 |
with gr.Row():
|
| 108 |
output_text = gr.Textbox(
|
| 109 |
label="Generated Text",
|
| 110 |
interactive=False,
|
| 111 |
+
lines=16,
|
| 112 |
+
max_lines=24,
|
| 113 |
scale=2,
|
| 114 |
)
|
| 115 |
with gr.Column(scale=1):
|
| 116 |
hume_audio_output = gr.Audio(label="Hume TTS Audio", type="filepath")
|
| 117 |
elevenlabs_audio_output = gr.Audio(label="ElevenLabs TTS Audio", type="filepath")
|
| 118 |
|
| 119 |
+
# Auto-fill the text input when a sample is selected
|
| 120 |
+
sample_prompt_dropdown.change(
|
| 121 |
+
fn=lambda choice: SAMPLE_PROMPTS[choice] if choice else "",
|
| 122 |
+
inputs=[sample_prompt_dropdown],
|
| 123 |
+
outputs=[prompt_input],
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
# Attach the validation, text generation, and TTS processing logic
|
| 127 |
generate_button.click(
|
| 128 |
fn=process_prompt,
|
src/sample_prompts.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
sample_prompts.py
|
| 3 |
+
|
| 4 |
+
This file contains predefined sample prompts to showcase the expressiveness of TTS models.
|
| 5 |
+
These prompts are structured to highlight different aspects of emotional tone, pacing, and rhythm.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
SAMPLE_PROMPTS = {
|
| 9 |
+
"🚀 Dramatic Monologue (Stranded Astronaut)":
|
| 10 |
+
"Write a short dramatic monologue from a lone astronaut stranded on Mars, "
|
| 11 |
+
"speaking to mission control for the last time. The tone should be reflective, "
|
| 12 |
+
"filled with awe and resignation as they describe the Martian landscape and their final thoughts.",
|
| 13 |
+
|
| 14 |
+
"📜 Poetic Sonnet (The Passage of Time)":
|
| 15 |
+
"Compose a sonnet about the passage of time, using vivid imagery and a flowing, melodic rhythm. "
|
| 16 |
+
"The poem should contrast fleeting moments with eternity, capturing both beauty and melancholy.",
|
| 17 |
+
|
| 18 |
+
"🐱 Whimsical Children's Story (Talking Cat)":
|
| 19 |
+
"Tell a short bedtime story about a mischievous talking cat who sneaks into a grand wizard’s library "
|
| 20 |
+
"at night and accidentally casts a spell that brings the books to life. "
|
| 21 |
+
"Make the tone playful, whimsical, and filled with wonder.",
|
| 22 |
+
|
| 23 |
+
"🔥 Intense Speech (Freedom & Justice)":
|
| 24 |
+
"Write a powerful speech delivered by a rebel leader rallying their people against a tyrant. "
|
| 25 |
+
"The speech should be passionate, filled with urgency and conviction, calling for freedom and justice.",
|
| 26 |
+
|
| 27 |
+
"👻 Mysterious Horror Scene (Haunted Lighthouse)":
|
| 28 |
+
"Describe a chilling ghostly encounter in an abandoned lighthouse on a foggy night. "
|
| 29 |
+
"The protagonist, alone and cold, begins hearing whispers from the shadows, "
|
| 30 |
+
"telling them secrets they were never meant to know."
|
| 31 |
+
}
|