Spaces:
Runtime error
Runtime error
Copy Boss
commited on
Commit
•
5c7add5
1
Parent(s):
e8f1a46
update-4
Browse files- app.py +6 -4
- requirements.txt +2 -1
app.py
CHANGED
@@ -2,6 +2,8 @@ import streamlit as st
|
|
2 |
import stable_whisper
|
3 |
import json
|
4 |
import torch
|
|
|
|
|
5 |
|
6 |
# Create a dropdown to select the model
|
7 |
model_name = st.selectbox("Select a model", ["base", "small", "medium", "large", "large-v2"])
|
@@ -15,10 +17,10 @@ audiofile = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
|
|
15 |
# Create a button to run the prediction
|
16 |
if st.button('Transcribe'):
|
17 |
if audiofile is not None:
|
18 |
-
# Read the audio file
|
19 |
-
audio_data =
|
20 |
-
# Convert the
|
21 |
-
audio_data = audio_data.float()
|
22 |
# Transcribe the audio file
|
23 |
result = model.transcribe(audio_data)
|
24 |
# Convert the result to JSON and display it
|
|
|
2 |
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"])
|
|
|
17 |
# Create a button to run the prediction
|
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
|
requirements.txt
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
streamlit
|
2 |
stable-ts
|
3 |
torch
|
4 |
-
numpy
|
|
|
|
1 |
streamlit
|
2 |
stable-ts
|
3 |
torch
|
4 |
+
numpy
|
5 |
+
soundfile
|