Copy Boss commited on
Commit
402ee04
1 Parent(s): 5c7add5
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -3,7 +3,7 @@ import stable_whisper
3
  import json
4
  import torch
5
  import soundfile as sf
6
- import io
7
 
8
  # Create a dropdown to select the model
9
  model_name = st.selectbox("Select a model", ["base", "small", "medium", "large", "large-v2"])
@@ -18,13 +18,16 @@ audiofile = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
18
  if st.button('Transcribe'):
19
  if audiofile is not None:
20
  # Read the audio file into a numpy array
21
- audio_data, _ = sf.read(io.BytesIO(audiofile.read()))
22
- # Convert the numpy array to a PyTorch tensor and ensure it's float32
23
  audio_data = torch.from_numpy(audio_data).float()
24
  # Transcribe the audio file
25
  result = model.transcribe(audio_data)
26
  # Convert the result to JSON and display it
27
- result_json = json.loads(result)
 
 
 
28
  st.json(result_json)
29
  else:
30
  st.write("Please upload an audio file.")
 
3
  import json
4
  import torch
5
  import soundfile as sf
6
+ from io import BytesIO
7
 
8
  # Create a dropdown to select the model
9
  model_name = st.selectbox("Select a model", ["base", "small", "medium", "large", "large-v2"])
 
18
  if st.button('Transcribe'):
19
  if audiofile is not None:
20
  # Read the audio file into a numpy array
21
+ audio_data, _ = sf.read(BytesIO(audiofile.read()))
22
+ # Convert the audio data to float
23
  audio_data = torch.from_numpy(audio_data).float()
24
  # Transcribe the audio file
25
  result = model.transcribe(audio_data)
26
  # Convert the result to JSON and display it
27
+ if isinstance(result, stable_whisper.WhisperResult):
28
+ result_json = result.to_dict() # replace with actual method if exists
29
+ else:
30
+ result_json = json.loads(result)
31
  st.json(result_json)
32
  else:
33
  st.write("Please upload an audio file.")