Spaces:
Running
Running
zach
commited on
Commit
Β·
bc5091e
1
Parent(s):
c8f7e68
Update documentation and fix typos across project
Browse files- src/config.py +2 -2
- src/constants.py +5 -4
- src/integrations/anthropic_api.py +6 -8
- src/integrations/elevenlabs_api.py +3 -3
- src/integrations/hume_api.py +5 -4
- src/theme.py +1 -1
src/config.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
"""
|
2 |
config.py
|
3 |
|
4 |
-
Global configuration and logger setup for the project.
|
5 |
-
constants and settings, such as the logging configuration and API constraints.
|
6 |
|
7 |
Key Features:
|
|
|
8 |
- Configures the logger for consistent logging across all modules.
|
9 |
- Dynamically sets the logging level based on the DEBUG environment variable.
|
10 |
"""
|
|
|
1 |
"""
|
2 |
config.py
|
3 |
|
4 |
+
Global configuration and logger setup for the project.
|
|
|
5 |
|
6 |
Key Features:
|
7 |
+
- Loads environment variables
|
8 |
- Configures the logger for consistent logging across all modules.
|
9 |
- Dynamically sets the logging level based on the DEBUG environment variable.
|
10 |
"""
|
src/constants.py
CHANGED
@@ -9,13 +9,14 @@ PROMPT_MIN_LENGTH: int = 10
|
|
9 |
PROMPT_MAX_LENGTH: int = 400
|
10 |
OPTION_ONE: str = "Option 1"
|
11 |
OPTION_TWO: str = "Option 2"
|
12 |
-
TROPHY_EMOJI = "π"
|
13 |
-
UNKNOWN_PROVIDER = "Unknown"
|
14 |
VOTE_FOR_OPTION_ONE: str = "Vote for option 1"
|
15 |
VOTE_FOR_OPTION_TWO: str = "Vote for option 2"
|
16 |
|
17 |
-
# A collection of pre-defined prompts categorized by theme, used to provide users with
|
18 |
-
|
|
|
19 |
'π Dramatic Monologue (Stranded Astronaut)':
|
20 |
'Write a short dramatic monologue from a lone astronaut stranded on Mars, speaking to '
|
21 |
'mission control for the last time. The tone should be reflective and filled with awe, conveying '
|
|
|
9 |
PROMPT_MAX_LENGTH: int = 400
|
10 |
OPTION_ONE: str = "Option 1"
|
11 |
OPTION_TWO: str = "Option 2"
|
12 |
+
TROPHY_EMOJI: str = "π"
|
13 |
+
UNKNOWN_PROVIDER: str = "Unknown"
|
14 |
VOTE_FOR_OPTION_ONE: str = "Vote for option 1"
|
15 |
VOTE_FOR_OPTION_TWO: str = "Vote for option 2"
|
16 |
|
17 |
+
# A collection of pre-defined prompts categorized by theme, used to provide users with
|
18 |
+
# inspiration for generating creative text for expressive TTS.
|
19 |
+
SAMPLE_PROMPTS: dict = {
|
20 |
'π Dramatic Monologue (Stranded Astronaut)':
|
21 |
'Write a short dramatic monologue from a lone astronaut stranded on Mars, speaking to '
|
22 |
'mission control for the last time. The tone should be reflective and filled with awe, conveying '
|
src/integrations/anthropic_api.py
CHANGED
@@ -35,13 +35,10 @@ from src.utils import truncate_text, validate_env_var
|
|
35 |
|
36 |
@dataclass(frozen=True)
|
37 |
class AnthropicConfig:
|
38 |
-
"""
|
39 |
-
Immutable configuration for interacting with the Anthropic API.
|
40 |
-
Includes client initialization for encapsulation.
|
41 |
-
"""
|
42 |
api_key: str = validate_env_var('ANTHROPIC_API_KEY')
|
43 |
-
model: ModelParam = 'claude-3-5-sonnet-latest'
|
44 |
-
max_tokens: int = 256
|
45 |
system_prompt: str = f"""You are an imaginative and articulate assistant, skilled in generating creative, concise, and engaging content that is perfectly suited for expressive speech synthesis.
|
46 |
|
47 |
Your task is to generate:
|
@@ -117,6 +114,7 @@ def generate_text_with_claude(prompt: str) -> str:
|
|
117 |
|
118 |
response = None
|
119 |
try:
|
|
|
120 |
response: Message = anthropic_config.client.messages.create(
|
121 |
model=anthropic_config.model,
|
122 |
max_tokens=anthropic_config.max_tokens,
|
@@ -125,12 +123,12 @@ def generate_text_with_claude(prompt: str) -> str:
|
|
125 |
)
|
126 |
logger.debug(f'API response received: {truncate_text(str(response))}')
|
127 |
|
128 |
-
# Validate response
|
129 |
if not hasattr(response, 'content'):
|
130 |
logger.error("Response is missing 'content'. Response: %s", response)
|
131 |
raise AnthropicError('Invalid API response: Missing "content".')
|
132 |
|
133 |
-
# Process response
|
134 |
blocks: Union[List[TextBlock], TextBlock, None] = response.content
|
135 |
if isinstance(blocks, list):
|
136 |
result = '\n\n'.join(block.text for block in blocks if isinstance(block, TextBlock))
|
|
|
35 |
|
36 |
@dataclass(frozen=True)
|
37 |
class AnthropicConfig:
|
38 |
+
"""Immutable configuration for interacting with the Anthropic API."""
|
|
|
|
|
|
|
39 |
api_key: str = validate_env_var('ANTHROPIC_API_KEY')
|
40 |
+
model: ModelParam = 'claude-3-5-sonnet-latest'
|
41 |
+
max_tokens: int = 256
|
42 |
system_prompt: str = f"""You are an imaginative and articulate assistant, skilled in generating creative, concise, and engaging content that is perfectly suited for expressive speech synthesis.
|
43 |
|
44 |
Your task is to generate:
|
|
|
114 |
|
115 |
response = None
|
116 |
try:
|
117 |
+
# Generate text using the Anthropic SDK
|
118 |
response: Message = anthropic_config.client.messages.create(
|
119 |
model=anthropic_config.model,
|
120 |
max_tokens=anthropic_config.max_tokens,
|
|
|
123 |
)
|
124 |
logger.debug(f'API response received: {truncate_text(str(response))}')
|
125 |
|
126 |
+
# Validate response
|
127 |
if not hasattr(response, 'content'):
|
128 |
logger.error("Response is missing 'content'. Response: %s", response)
|
129 |
raise AnthropicError('Invalid API response: Missing "content".')
|
130 |
|
131 |
+
# Process response
|
132 |
blocks: Union[List[TextBlock], TextBlock, None] = response.content
|
133 |
if isinstance(blocks, list):
|
134 |
result = '\n\n'.join(block.text for block in blocks if isinstance(block, TextBlock))
|
src/integrations/elevenlabs_api.py
CHANGED
@@ -38,7 +38,7 @@ class ElevenLabsConfig:
|
|
38 |
"""Immutable configuration for interacting with the ElevenLabs TTS API."""
|
39 |
api_key: str = validate_env_var('ELEVENLABS_API_KEY')
|
40 |
model_id: str = 'eleven_multilingual_v2' # ElevenLab's most emotionally expressive model
|
41 |
-
output_format: str = 'mp3_44100_128' # Output format of the generated audio
|
42 |
top_voices: list[str] = (
|
43 |
'pNInz6obpgDQGcFmaJgB', # Adam
|
44 |
'ErXwobaYiN019PkySvjV', # Antoni
|
@@ -109,10 +109,10 @@ def text_to_speech_with_elevenlabs(text: str) -> bytes:
|
|
109 |
logger.debug(f'Synthesizing speech from text with ElevenLabs. Text length: {len(text)} characters.')
|
110 |
|
111 |
try:
|
112 |
-
#
|
113 |
audio_iterator = elevenlabs_config.client.text_to_speech.convert(
|
114 |
text=text,
|
115 |
-
voice_id=elevenlabs_config.random_voice_id,
|
116 |
model_id=elevenlabs_config.model_id,
|
117 |
output_format=elevenlabs_config.output_format,
|
118 |
)
|
|
|
38 |
"""Immutable configuration for interacting with the ElevenLabs TTS API."""
|
39 |
api_key: str = validate_env_var('ELEVENLABS_API_KEY')
|
40 |
model_id: str = 'eleven_multilingual_v2' # ElevenLab's most emotionally expressive model
|
41 |
+
output_format: str = 'mp3_44100_128' # Output format of the generated audio
|
42 |
top_voices: list[str] = (
|
43 |
'pNInz6obpgDQGcFmaJgB', # Adam
|
44 |
'ErXwobaYiN019PkySvjV', # Antoni
|
|
|
109 |
logger.debug(f'Synthesizing speech from text with ElevenLabs. Text length: {len(text)} characters.')
|
110 |
|
111 |
try:
|
112 |
+
# Synthesize speech using the ElevenLabs SDK
|
113 |
audio_iterator = elevenlabs_config.client.text_to_speech.convert(
|
114 |
text=text,
|
115 |
+
voice_id=elevenlabs_config.random_voice_id,
|
116 |
model_id=elevenlabs_config.model_id,
|
117 |
output_format=elevenlabs_config.output_format,
|
118 |
)
|
src/integrations/hume_api.py
CHANGED
@@ -11,11 +11,11 @@ Key Features:
|
|
11 |
- Provides detailed logging for debugging and error tracking.
|
12 |
|
13 |
Classes:
|
14 |
-
- HumeConfig: Immutable configuration for interacting with Hume's
|
15 |
- HumeError: Custom exception for Hume API-related errors.
|
16 |
|
17 |
Functions:
|
18 |
-
- text_to_speech_with_hume: Synthesizes speech from text using Hume's
|
19 |
"""
|
20 |
|
21 |
# Standard Library Imports
|
@@ -38,9 +38,9 @@ class HumeConfig:
|
|
38 |
"""Immutable configuration for interacting with the Hume TTS API."""
|
39 |
tts_endpoint_url: str = 'https://api.hume.ai/v0/tts'
|
40 |
api_key: str = validate_env_var('HUME_API_KEY')
|
41 |
-
voices: List[str] = ('ITO', 'KORA', 'STELLA')
|
42 |
audio_format: str = 'wav'
|
43 |
-
headers: dict = None
|
44 |
|
45 |
def __post_init__(self):
|
46 |
# Validate required attributes
|
@@ -110,6 +110,7 @@ def text_to_speech_with_hume(prompt: str, text: str) -> bytes:
|
|
110 |
}
|
111 |
|
112 |
try:
|
|
|
113 |
response = requests.post(
|
114 |
url=hume_config.tts_endpoint_url,
|
115 |
headers=hume_config.headers,
|
|
|
11 |
- Provides detailed logging for debugging and error tracking.
|
12 |
|
13 |
Classes:
|
14 |
+
- HumeConfig: Immutable configuration for interacting with Hume's TTS API.
|
15 |
- HumeError: Custom exception for Hume API-related errors.
|
16 |
|
17 |
Functions:
|
18 |
+
- text_to_speech_with_hume: Synthesizes speech from text using Hume's TTS API.
|
19 |
"""
|
20 |
|
21 |
# Standard Library Imports
|
|
|
38 |
"""Immutable configuration for interacting with the Hume TTS API."""
|
39 |
tts_endpoint_url: str = 'https://api.hume.ai/v0/tts'
|
40 |
api_key: str = validate_env_var('HUME_API_KEY')
|
41 |
+
voices: List[str] = ('ITO', 'KORA', 'STELLA')
|
42 |
audio_format: str = 'wav'
|
43 |
+
headers: dict = None
|
44 |
|
45 |
def __post_init__(self):
|
46 |
# Validate required attributes
|
|
|
110 |
}
|
111 |
|
112 |
try:
|
113 |
+
# Synthesize speech using the Hume TTS API
|
114 |
response = requests.post(
|
115 |
url=hume_config.tts_endpoint_url,
|
116 |
headers=hume_config.headers,
|
src/theme.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
"""
|
2 |
theme.py
|
3 |
|
4 |
-
|
5 |
- For more information on Gradio themes see: https://www.gradio.app/docs/gradio/themes
|
6 |
- For manual styling with css, see /src/assets/styles.css
|
7 |
"""
|
|
|
1 |
"""
|
2 |
theme.py
|
3 |
|
4 |
+
This module defines a custom Gradio theme.
|
5 |
- For more information on Gradio themes see: https://www.gradio.app/docs/gradio/themes
|
6 |
- For manual styling with css, see /src/assets/styles.css
|
7 |
"""
|