stable-ts / app.py
Copy Boss
update
30f568b
raw
history blame
913 Bytes
import streamlit as st
import stable_whisper
import json
import soundfile as sf
import io
# Create a dropdown to select the model
model_name = st.selectbox("Select a model", ["base", "small", "medium", "large", "large-v2"])
# Load the selected model
model = stable_whisper.load_model(model_name)
# Create a file uploader for the audio file
audiofile = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
# Create a button to run the prediction
if st.button('Transcribe'):
if audiofile is not None:
# Read the audio file
file_bytes = audiofile.read()
audio_data, sample_rate = sf.read(io.BytesIO(file_bytes))
# Transcribe the audio file
result = model.transcribe(audio_data)
# Convert the result to JSON and display it
result_json = json.loads(result)
st.json(result_json)
else:
st.write("Please upload an audio file.")