mobina1380 commited on
Commit
b5c343b
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -4,19 +4,28 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
 
 
8
  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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -55,7 +64,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,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ from gtts import gTTS
8
+ import uuid
9
+ import os
10
  from Gradio_UI import GradioUI
11
 
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def text_to_speech(text: str, lang: str = "en") -> str:
15
+ """Converts a given text to speech and returns the file path to the audio file.
 
16
  Args:
17
+ text: The text you want to convert to speech.
18
+ lang: The language code for the speech (e.g., 'en' for English, 'fr' for French).
19
  """
20
+ try:
21
+ tts = gTTS(text=text, lang=lang)
22
+ filename = f"{uuid.uuid4()}.mp3"
23
+ filepath = os.path.join("outputs", filename)
24
+ os.makedirs("outputs", exist_ok=True)
25
+ tts.save(filepath)
26
+ return f"Audio file saved at: {filepath}"
27
+ except Exception as e:
28
+ return f"Failed to convert text to speech: {str(e)}"
29
 
30
  @tool
31
  def get_current_time_in_timezone(timezone: str) -> str:
 
64
 
65
  agent = CodeAgent(
66
  model=model,
67
+ tools=[final_answer,text_to_speech], ## add your tools here (don't remove final answer)
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,