Spaces:
Runtime error
Runtime error
added download functionality
Browse files
app.py
CHANGED
@@ -8,6 +8,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
|
@@ -29,18 +30,19 @@ def generate_sound(sound_type: str, duration: int) -> str:
|
|
29 |
duration: Duration of the sound in seconds.
|
30 |
|
31 |
Returns:
|
32 |
-
|
33 |
"""
|
34 |
try:
|
35 |
-
duration_ms = duration * 1000
|
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"
|
42 |
sound.export(output_path, format="wav")
|
43 |
-
|
|
|
44 |
|
45 |
except Exception as e:
|
46 |
return f"Error generating sound: {str(e)}"
|
@@ -85,6 +87,7 @@ agent = CodeAgent(
|
|
85 |
name=None,
|
86 |
description=None,
|
87 |
prompt_templates=prompt_templates
|
|
|
88 |
)
|
89 |
|
90 |
# Start the UI with processing time display
|
|
|
8 |
from huggingface_hub import InferenceClient
|
9 |
from pydub.generators import WhiteNoise
|
10 |
from pydub import AudioSegment
|
11 |
+
from gradio import Files
|
12 |
|
13 |
from Gradio_UI import GradioUI
|
14 |
import os
|
|
|
30 |
duration: Duration of the sound in seconds.
|
31 |
|
32 |
Returns:
|
33 |
+
Download link
|
34 |
"""
|
35 |
try:
|
36 |
+
duration_ms = duration * 1000
|
37 |
if sound_type == "rain":
|
38 |
sound = WhiteNoise().to_audio_segment(duration=duration_ms).low_pass_filter(5000)
|
39 |
else:
|
40 |
return f"Unsupported sound type: {sound_type}"
|
41 |
|
42 |
+
output_path = f"rain_{duration}s.wav"
|
43 |
sound.export(output_path, format="wav")
|
44 |
+
|
45 |
+
return Files(output_path) # This makes the file downloadable in Gradio
|
46 |
|
47 |
except Exception as e:
|
48 |
return f"Error generating sound: {str(e)}"
|
|
|
87 |
name=None,
|
88 |
description=None,
|
89 |
prompt_templates=prompt_templates
|
90 |
+
output_modality="file"
|
91 |
)
|
92 |
|
93 |
# Start the UI with processing time display
|