lchumaceiro commited on
Commit
6446aa5
·
verified ·
1 Parent(s): eb54186
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -19,20 +19,21 @@ if hf_token:
19
  else:
20
  print("⚠️ Hugging Face API token is missing! Set HF_TOKEN in Space secrets.")
21
 
22
- # ✅ Sound generation tool with type hints and docstring descriptions
23
  @tool
24
  def generate_sound(sound_type: str, duration: int) -> str:
25
  """
26
  Generates a simple sound based on the specified type and duration.
27
-
28
- Args:
29
  sound_type (str): The type of sound to generate (e.g., 'rain', 'white_noise').
30
  duration (int): The duration of the sound in seconds.
31
 
32
  Returns:
33
- str: The file path of the generated sound file.
34
  """
35
  try:
 
36
  duration_ms = duration * 1000
37
  output_path = f"/home/user/app/{sound_type}_{duration}s.wav"
38
 
@@ -41,12 +42,14 @@ def generate_sound(sound_type: str, duration: int) -> str:
41
  else:
42
  return f"Unsupported sound type: {sound_type}"
43
 
 
44
  sound.export(output_path, format="wav")
45
  return output_path # ✅ Returns a valid file path for Gradio
46
 
47
  except Exception as e:
48
  return f"Error generating sound: {str(e)}"
49
 
 
50
  # ✅ Time zone tool
51
  @tool
52
  def get_current_time_in_timezone(timezone: str) -> str:
 
19
  else:
20
  print("⚠️ Hugging Face API token is missing! Set HF_TOKEN in Space secrets.")
21
 
22
+ # ✅ Sound generation tool with explicitly formatted docstring
23
  @tool
24
  def generate_sound(sound_type: str, duration: int) -> str:
25
  """
26
  Generates a simple sound based on the specified type and duration.
27
+
28
+ Arguments:
29
  sound_type (str): The type of sound to generate (e.g., 'rain', 'white_noise').
30
  duration (int): The duration of the sound in seconds.
31
 
32
  Returns:
33
+ str: Path to the generated sound file (e.g., '/home/user/app/rain_3s.wav').
34
  """
35
  try:
36
+ # Convert duration to milliseconds
37
  duration_ms = duration * 1000
38
  output_path = f"/home/user/app/{sound_type}_{duration}s.wav"
39
 
 
42
  else:
43
  return f"Unsupported sound type: {sound_type}"
44
 
45
+ # Export sound to the specified file path
46
  sound.export(output_path, format="wav")
47
  return output_path # ✅ Returns a valid file path for Gradio
48
 
49
  except Exception as e:
50
  return f"Error generating sound: {str(e)}"
51
 
52
+
53
  # ✅ Time zone tool
54
  @tool
55
  def get_current_time_in_timezone(timezone: str) -> str: