Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,13 +67,16 @@ def generate_sfx(text, duration=30):
|
|
| 67 |
|
| 68 |
# Calculate total samples for the specified duration
|
| 69 |
total_samples = duration * 22050 # Samples for 30 seconds
|
|
|
|
| 70 |
# Generate audio samples
|
| 71 |
generated_samples = model.predict(input_data)
|
| 72 |
|
| 73 |
-
#
|
| 74 |
-
if
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
# Convert the prediction to audio data
|
| 78 |
audio_data = convert_to_audio(generated_samples)
|
| 79 |
|
|
@@ -83,12 +86,12 @@ def generate_sfx(text, duration=30):
|
|
| 83 |
|
| 84 |
return output_filename
|
| 85 |
|
| 86 |
-
# Define the Gradio interface
|
| 87 |
interface = gr.Interface(
|
| 88 |
fn=generate_sfx,
|
| 89 |
inputs=[
|
| 90 |
gr.Textbox(label="Enter a Word", placeholder="Write a Word To Convert it into SFX Sound"),
|
| 91 |
-
gr.Slider(label="Duration (seconds)", minimum=
|
| 92 |
],
|
| 93 |
outputs=gr.Audio(label="Generated SFX", type="filepath"),
|
| 94 |
live=False,
|
|
|
|
| 67 |
|
| 68 |
# Calculate total samples for the specified duration
|
| 69 |
total_samples = duration * 22050 # Samples for 30 seconds
|
| 70 |
+
|
| 71 |
# Generate audio samples
|
| 72 |
generated_samples = model.predict(input_data)
|
| 73 |
|
| 74 |
+
# Ensure generated samples meet the required duration
|
| 75 |
+
if generated_samples.shape[1] < total_samples:
|
| 76 |
+
# Pad with zeros if not enough audio is generated
|
| 77 |
+
padding = np.zeros((1, total_samples - generated_samples.shape[1]))
|
| 78 |
+
generated_samples = np.concatenate([generated_samples, padding], axis=1)
|
| 79 |
+
|
| 80 |
# Convert the prediction to audio data
|
| 81 |
audio_data = convert_to_audio(generated_samples)
|
| 82 |
|
|
|
|
| 86 |
|
| 87 |
return output_filename
|
| 88 |
|
| 89 |
+
# Define the Gradio interface with updated slider settings
|
| 90 |
interface = gr.Interface(
|
| 91 |
fn=generate_sfx,
|
| 92 |
inputs=[
|
| 93 |
gr.Textbox(label="Enter a Word", placeholder="Write a Word To Convert it into SFX Sound"),
|
| 94 |
+
gr.Slider(label="Duration (seconds)", minimum=2, maximum=20, value=5) # Set duration options
|
| 95 |
],
|
| 96 |
outputs=gr.Audio(label="Generated SFX", type="filepath"),
|
| 97 |
live=False,
|