musdfakoc commited on
Commit
99dc7e5
·
verified ·
1 Parent(s): eaee834

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -164,8 +164,12 @@ def spectrogram_to_audio(magnitude_spectrogram):
164
  return audio
165
 
166
 
167
- # Function to generate audio from an uploaded image
168
  def generate_audio_from_image(image):
 
 
 
 
 
169
  test_img = image_transform(image).unsqueeze(0).to(device) # Preprocess image
170
 
171
  # Generate sound spectrogram from the image using the loaded generator
@@ -178,6 +182,7 @@ def generate_audio_from_image(image):
178
  # Convert audio tensor to numpy and return it for Gradio to handle
179
  return generated_audio.numpy(), sample_rate
180
 
 
181
  # Gradio Interface
182
  def main():
183
  global generator # Declare the generator object globally
@@ -190,8 +195,9 @@ def main():
190
 
191
  # Gradio interface: allow users to upload an image and generate audio
192
  iface = gr.Interface(fn=generate_audio_from_image,
193
- inputs=gr.Image(type="pil"),
194
- outputs=gr.Audio(type="numpy", label="Generated Audio"))
 
195
 
196
  iface.launch()
197
 
 
164
  return audio
165
 
166
 
 
167
  def generate_audio_from_image(image):
168
+ if image is None:
169
+ raise ValueError("The uploaded image is 'None'. Please check the Gradio input.")
170
+
171
+ # Ensure the image is in the right format
172
+ print(f"Image received: {type(image)}") # Debugging: Check if image is received
173
  test_img = image_transform(image).unsqueeze(0).to(device) # Preprocess image
174
 
175
  # Generate sound spectrogram from the image using the loaded generator
 
182
  # Convert audio tensor to numpy and return it for Gradio to handle
183
  return generated_audio.numpy(), sample_rate
184
 
185
+
186
  # Gradio Interface
187
  def main():
188
  global generator # Declare the generator object globally
 
195
 
196
  # Gradio interface: allow users to upload an image and generate audio
197
  iface = gr.Interface(fn=generate_audio_from_image,
198
+ inputs=gr.Image(type="pil"), # PIL type image
199
+ outputs=gr.Audio(type="numpy", label="Generated Audio"))
200
+
201
 
202
  iface.launch()
203