adi-123 commited on
Commit
0b2245a
1 Parent(s): af7de75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -26
app.py CHANGED
@@ -15,11 +15,7 @@ def classify_audio(audio_file_path):
15
  headers=headers,
16
  files={"file": audio_file}
17
  )
18
- # Check the response status and return JSON if successful, or an error message
19
- if response.status_code == 200:
20
- return response.json()
21
- else:
22
- return {"error": f"Failed to classify audio. Status code: {response.status_code}"}
23
 
24
  # Streamlit interface
25
  st.title("Audio Classifier")
@@ -28,12 +24,8 @@ st.title("Audio Classifier")
28
  audio_folder = "audio_files"
29
 
30
  # List the audio files in the folder
31
- try:
32
- audio_files = os.listdir(audio_folder)
33
- audio_file_options = [f for f in audio_files if f.endswith(('.mp3', '.wav'))]
34
- except Exception as e:
35
- st.error(f"Error accessing the audio files: {e}")
36
- st.stop()
37
 
38
  # Dropdown to select an audio file
39
  selected_file = st.selectbox("Select an audio file:", audio_file_options)
@@ -48,21 +40,6 @@ if st.button("Classify"):
48
 
49
  # Get and display the classification results
50
  results = classify_audio(audio_file_path)
51
-
52
- # Check for errors
53
- if "error" in results:
54
- st.error(results["error"])
55
- else:
56
- st.write("Results:")
57
- # Loop through each result in the list of results
58
- for result in results:
59
- # Check if result is a dictionary with 'label' and 'score' keys
60
- if isinstance(result, dict) and 'label' in result and 'score' in result:
61
- st.write(f"Label: {result['label']}, Confidence: {result['score']:.2f}")
62
- else:
63
- st.error(f"Unexpected result format: {result}")
64
- # Get and display the classification results
65
- results = classify_audio(audio_file_path)
66
  st.write("Results:")
67
  for result in results:
68
  st.write(f"Label: {result['label']}, Confidence: {result['score']:.2f}")
 
15
  headers=headers,
16
  files={"file": audio_file}
17
  )
18
+ return response.json()
 
 
 
 
19
 
20
  # Streamlit interface
21
  st.title("Audio Classifier")
 
24
  audio_folder = "audio_files"
25
 
26
  # List the audio files in the folder
27
+ audio_files = os.listdir(audio_folder)
28
+ audio_file_options = [f for f in audio_files if f.endswith(('.mp3', '.wav'))]
 
 
 
 
29
 
30
  # Dropdown to select an audio file
31
  selected_file = st.selectbox("Select an audio file:", audio_file_options)
 
40
 
41
  # Get and display the classification results
42
  results = classify_audio(audio_file_path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  st.write("Results:")
44
  for result in results:
45
  st.write(f"Label: {result['label']}, Confidence: {result['score']:.2f}")