Spaces:
Sleeping
Sleeping
fixed tool
Browse files
app.py
CHANGED
@@ -6,6 +6,8 @@ import yaml
|
|
6 |
import time
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
from huggingface_hub import InferenceClient
|
|
|
|
|
9 |
|
10 |
from Gradio_UI import GradioUI
|
11 |
import os
|
@@ -20,18 +22,26 @@ else:
|
|
20 |
# Sound generation tool
|
21 |
@tool
|
22 |
def generate_sound(sound_type: str, duration: int) -> str:
|
23 |
-
"""
|
|
|
24 |
Args:
|
25 |
-
sound_type:
|
26 |
-
duration:
|
|
|
|
|
|
|
27 |
"""
|
28 |
try:
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
return f"Generated {sound_type} sound for {duration} seconds. Link: {response.json().get('sound_url', 'N/A')}"
|
33 |
else:
|
34 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
35 |
except Exception as e:
|
36 |
return f"Error generating sound: {str(e)}"
|
37 |
|
@@ -67,7 +77,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
67 |
|
68 |
agent = CodeAgent(
|
69 |
model=model,
|
70 |
-
tools=[final_answer, generate_sound], #
|
71 |
max_steps=6,
|
72 |
verbosity_level=1,
|
73 |
grammar=None,
|
|
|
6 |
import time
|
7 |
from tools.final_answer import FinalAnswerTool
|
8 |
from huggingface_hub import InferenceClient
|
9 |
+
from pydub.generators import WhiteNoise
|
10 |
+
from pydub import AudioSegment
|
11 |
|
12 |
from Gradio_UI import GradioUI
|
13 |
import os
|
|
|
22 |
# Sound generation tool
|
23 |
@tool
|
24 |
def generate_sound(sound_type: str, duration: int) -> str:
|
25 |
+
"""Generates a simple sound based on the specified type and duration.
|
26 |
+
|
27 |
Args:
|
28 |
+
sound_type: Type of sound to generate (e.g., 'rain', 'white_noise').
|
29 |
+
duration: Duration of the sound in seconds.
|
30 |
+
|
31 |
+
Returns:
|
32 |
+
Path to the generated audio file.
|
33 |
"""
|
34 |
try:
|
35 |
+
duration_ms = duration * 1000 # Convert to milliseconds
|
36 |
+
if sound_type == "rain":
|
37 |
+
sound = WhiteNoise().to_audio_segment(duration=duration_ms).low_pass_filter(5000)
|
|
|
38 |
else:
|
39 |
+
return f"Unsupported sound type: {sound_type}"
|
40 |
+
|
41 |
+
output_path = f"/tmp/{sound_type}_{duration}s.wav"
|
42 |
+
sound.export(output_path, format="wav")
|
43 |
+
return output_path
|
44 |
+
|
45 |
except Exception as e:
|
46 |
return f"Error generating sound: {str(e)}"
|
47 |
|
|
|
77 |
|
78 |
agent = CodeAgent(
|
79 |
model=model,
|
80 |
+
tools=[final_answer, generate_sound], # Add your tool
|
81 |
max_steps=6,
|
82 |
verbosity_level=1,
|
83 |
grammar=None,
|