Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -149,14 +149,11 @@ def spectrogram_to_audio(magnitude_spectrogram):
|
|
149 |
return audio
|
150 |
|
151 |
|
152 |
-
import numpy as np
|
153 |
-
|
154 |
def generate_audio_from_image(image):
|
155 |
if image is None:
|
156 |
raise ValueError("The uploaded image is 'None'. Please check the Gradio input.")
|
157 |
|
158 |
# Ensure the image is in the right format
|
159 |
-
print(f"Image received: {type(image)}") # Debugging: Check if image is received
|
160 |
test_img = image_transform(image).unsqueeze(0).to(device) # Preprocess image
|
161 |
|
162 |
# Generate sound spectrogram from the image using the loaded generator
|
@@ -177,14 +174,11 @@ def generate_audio_from_image(image):
|
|
177 |
# Convert to the required format (e.g., float32)
|
178 |
generated_audio = generated_audio.astype(np.float32)
|
179 |
|
180 |
-
# Transpose to
|
181 |
generated_audio = generated_audio.T
|
182 |
|
183 |
-
#
|
184 |
-
|
185 |
-
|
186 |
-
return generated_audio, sample_rate
|
187 |
-
|
188 |
|
189 |
|
190 |
# Gradio Interface
|
|
|
149 |
return audio
|
150 |
|
151 |
|
|
|
|
|
152 |
def generate_audio_from_image(image):
|
153 |
if image is None:
|
154 |
raise ValueError("The uploaded image is 'None'. Please check the Gradio input.")
|
155 |
|
156 |
# Ensure the image is in the right format
|
|
|
157 |
test_img = image_transform(image).unsqueeze(0).to(device) # Preprocess image
|
158 |
|
159 |
# Generate sound spectrogram from the image using the loaded generator
|
|
|
174 |
# Convert to the required format (e.g., float32)
|
175 |
generated_audio = generated_audio.astype(np.float32)
|
176 |
|
177 |
+
# Transpose to (samples, channels) for stereo
|
178 |
generated_audio = generated_audio.T
|
179 |
|
180 |
+
# Return the audio and the sample rate (ensure sample rate is an integer)
|
181 |
+
return generated_audio, int(sample_rate)
|
|
|
|
|
|
|
182 |
|
183 |
|
184 |
# Gradio Interface
|