rm-dev-null commited on
Commit
ab343a7
·
verified ·
1 Parent(s): bad268f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -27,6 +27,11 @@ async def identify_track(shazam, audio_chunk):
27
  try:
28
  temp_file = 'temp_chunk.wav'
29
  audio_chunk.export(temp_file, format='wav')
 
 
 
 
 
30
  result = await shazam.recognize_file(temp_file)
31
  os.remove(temp_file) # Clean up temporary file
32
  if result and 'track' in result:
@@ -63,6 +68,11 @@ async def process_dj_set(track_url, progress=gr.Progress()):
63
  return download_status, ""
64
 
65
  status = "Processing audio..."
 
 
 
 
 
66
  audio = AudioSegment.from_wav('track.wav')
67
 
68
  chunk_duration = 30000 # 30 seconds
@@ -130,4 +140,4 @@ with gr.Blocks(css=css) as demo:
130
  run_button.click(process_dj_set, inputs=track_url_input, outputs=[result_output, download_button])
131
 
132
  if __name__ == "__main__":
133
- demo.launch(share=True)
 
27
  try:
28
  temp_file = 'temp_chunk.wav'
29
  audio_chunk.export(temp_file, format='wav')
30
+
31
+ # Ensure temp_file exists and is not a directory
32
+ if not os.path.isfile(temp_file):
33
+ raise FileNotFoundError(f"Temporary file '{temp_file}' does not exist or is not a valid file.")
34
+
35
  result = await shazam.recognize_file(temp_file)
36
  os.remove(temp_file) # Clean up temporary file
37
  if result and 'track' in result:
 
68
  return download_status, ""
69
 
70
  status = "Processing audio..."
71
+
72
+ # Ensure 'track.wav' exists and is not a directory
73
+ if not os.path.isfile('track.wav'):
74
+ raise FileNotFoundError("Downloaded audio file 'track.wav' does not exist or is not valid.")
75
+
76
  audio = AudioSegment.from_wav('track.wav')
77
 
78
  chunk_duration = 30000 # 30 seconds
 
140
  run_button.click(process_dj_set, inputs=track_url_input, outputs=[result_output, download_button])
141
 
142
  if __name__ == "__main__":
143
+ demo.launch(share=False)