Update app.py
#482
by Anuragleo67 - opened
app.py
CHANGED
|
@@ -9,14 +9,32 @@ from Gradio_UI import GradioUI
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -55,7 +73,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def generate_audio_gtts(text: str, language: str = "en", slow: bool = False) -> str:
|
| 13 |
+
"""A tool that generates audio from text using Google Text-to-Speech.
|
|
|
|
| 14 |
Args:
|
| 15 |
+
text: the text content to convert into speech audio
|
| 16 |
+
language: the language code for speech synthesis (e.g., 'en' for English, 'es' for Spanish, 'fr' for French)
|
| 17 |
+
slow: whether to generate speech at a slower rate for better clarity
|
| 18 |
"""
|
| 19 |
+
try:
|
| 20 |
+
from gtts import gTTS
|
| 21 |
+
import os
|
| 22 |
+
|
| 23 |
+
# Create gTTS object
|
| 24 |
+
tts = gTTS(text=text, lang=language, slow=slow)
|
| 25 |
+
|
| 26 |
+
# Save audio file with timestamp
|
| 27 |
+
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 28 |
+
filename = f"gtts_audio_{timestamp}.mp3"
|
| 29 |
+
|
| 30 |
+
tts.save(filename)
|
| 31 |
+
|
| 32 |
+
return f"Audio generated successfully using Google TTS and saved as: {filename}"
|
| 33 |
+
|
| 34 |
+
except ImportError:
|
| 35 |
+
return "Error: gTTS library not installed. Please install with: pip install gtts"
|
| 36 |
+
except Exception as e:
|
| 37 |
+
return f"Error generating audio with gTTS: {str(e)}"
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 73 |
|
| 74 |
agent = CodeAgent(
|
| 75 |
model=model,
|
| 76 |
+
tools=[final_answer, generate_audio_gtts], ## add your tools here (don't remove final answer)
|
| 77 |
max_steps=6,
|
| 78 |
verbosity_level=1,
|
| 79 |
grammar=None,
|