sam9407287 commited on
Commit
7392fa4
·
verified ·
1 Parent(s): 4869d4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -38
app.py CHANGED
@@ -1,12 +1,9 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
- import os
8
- import scipy.io.wavfile
9
- from transformers import BarkModel, BarkTokenizer
10
 
11
  from Gradio_UI import GradioUI
12
 
@@ -16,39 +13,6 @@ print(transformers.__version__)
16
  tokenizer = BarkTokenizer.from_pretrained("suno/bark-small")
17
  model = BarkModel.from_pretrained("suno/bark-small")
18
 
19
-
20
- # Define the text-to-speech tool
21
- @tool
22
- def text_to_speech(text: str) -> bytes:
23
- """
24
- Converts text to speech using the Bark model.
25
-
26
- Args:
27
- text: The text to be converted to speech.
28
-
29
- Returns:
30
- bytes: The audio data in WAV format.
31
- """
32
- try:
33
- inputs = tokenizer(text, return_tensors="pt")
34
- audio_array = model.generate(**inputs)
35
- # Convert the generated audio array to a NumPy array
36
- audio_array = audio_array.cpu().numpy()
37
-
38
- # Save the audio array as a WAV file
39
- rate = 16000 # Bark model sample rate
40
- filename = "output.wav"
41
- scipy.io.wavfile.write(filename, rate, audio_array)
42
-
43
- # Read the WAV file and convert it to bytes
44
- with open(filename, "rb") as f:
45
- audio_bytes = f.read()
46
-
47
- return audio_bytes
48
-
49
- except Exception as e:
50
- return f"Error converting text to speech: {str(e)}".encode('utf-8')
51
-
52
  # Define the get current time in timezone tool
53
  @tool
54
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -87,7 +51,7 @@ with open("prompts.yaml", 'r') as stream:
87
 
88
  agent = CodeAgent(
89
  model=model,
90
- tools=[final_answer, image_generation_tool, text_to_speech], ## add your tools here (don't remove final answer)
91
  max_steps=6,
92
  verbosity_level=1,
93
  grammar=None,
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
13
  tokenizer = BarkTokenizer.from_pretrained("suno/bark-small")
14
  model = BarkModel.from_pretrained("suno/bark-small")
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Define the get current time in timezone tool
17
  @tool
18
  def get_current_time_in_timezone(timezone: str) -> str:
 
51
 
52
  agent = CodeAgent(
53
  model=model,
54
+ tools=[final_answer, image_generation_tool, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
55
  max_steps=6,
56
  verbosity_level=1,
57
  grammar=None,