Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,9 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 13 |
@tool
|
|
@@ -20,25 +22,25 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 20 |
"""
|
| 21 |
return "What magic will you build ?"
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
@tool
|
| 24 |
-
def text_to_speech_kokoro(text: str, voice: str = 'af_heart',
|
| 25 |
-
"""
|
|
|
|
| 26 |
Args:
|
| 27 |
text: The text to be converted to speech.
|
| 28 |
voice: The voice to use for speech synthesis (default is 'af_heart').
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
"""
|
| 31 |
try:
|
| 32 |
-
# Import necessary libraries
|
| 33 |
-
from kokoro import KPipeline
|
| 34 |
-
import soundfile as sf
|
| 35 |
-
import os
|
| 36 |
-
|
| 37 |
-
# Initialize the Kokoro pipeline
|
| 38 |
-
pipeline = KPipeline(lang_code=lang_code)
|
| 39 |
-
|
| 40 |
# Generate speech audio
|
| 41 |
-
generator = pipeline(text, voice=voice, speed=
|
| 42 |
audio_files = []
|
| 43 |
|
| 44 |
# Save each audio segment to a file
|
|
@@ -52,7 +54,6 @@ def text_to_speech_kokoro(text: str, voice: str = 'af_heart', lang_code: str = '
|
|
| 52 |
return f"Error generating speech: {str(e)}"
|
| 53 |
|
| 54 |
|
| 55 |
-
|
| 56 |
@tool
|
| 57 |
def search_dad_jokes(term: str) -> str:
|
| 58 |
"""A tool that searches for dad jokes containing a specific term.
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
+
from kokoro import KPipeline
|
| 11 |
+
import soundfile as sf
|
| 12 |
+
import os
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
|
|
|
| 22 |
"""
|
| 23 |
return "What magic will you build ?"
|
| 24 |
|
| 25 |
+
|
| 26 |
+
# Initialize the Kokoro pipeline
|
| 27 |
+
pipeline = KPipeline(lang_code='a') # 'a' stands for American English
|
| 28 |
+
|
| 29 |
@tool
|
| 30 |
+
def text_to_speech_kokoro(text: str, voice: str = 'af_heart', speed: float = 1.0) -> str:
|
| 31 |
+
"""Convert text to speech using the Kokoro-82M model.
|
| 32 |
+
|
| 33 |
Args:
|
| 34 |
text: The text to be converted to speech.
|
| 35 |
voice: The voice to use for speech synthesis (default is 'af_heart').
|
| 36 |
+
speed: The speed of the speech (default is 1.0).
|
| 37 |
+
|
| 38 |
+
Returns:
|
| 39 |
+
The filename of the generated audio file.
|
| 40 |
"""
|
| 41 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
# Generate speech audio
|
| 43 |
+
generator = pipeline(text, voice=voice, speed=speed, split_pattern=r'\n+')
|
| 44 |
audio_files = []
|
| 45 |
|
| 46 |
# Save each audio segment to a file
|
|
|
|
| 54 |
return f"Error generating speech: {str(e)}"
|
| 55 |
|
| 56 |
|
|
|
|
| 57 |
@tool
|
| 58 |
def search_dad_jokes(term: str) -> str:
|
| 59 |
"""A tool that searches for dad jokes containing a specific term.
|