Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import streamlit as st
|
2 |
from faster_whisper import WhisperModel
|
3 |
import logging
|
|
|
|
|
4 |
|
5 |
# Configure logging for debugging purposes
|
6 |
logging.basicConfig()
|
@@ -15,13 +17,21 @@ def format_timestamp(seconds):
|
|
15 |
|
16 |
def transcribe(audio_file, model_size):
|
17 |
# Initialize the Whisper model based on the selected model size
|
18 |
-
device = "cpu" #
|
19 |
-
compute_type = "int8" #
|
20 |
|
21 |
model = WhisperModel(model_size, device=device, compute_type=compute_type)
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
23 |
# Transcribe the audio file
|
24 |
-
segments, _ = model.transcribe(
|
|
|
|
|
|
|
25 |
|
26 |
# Format and gather transcription with enhanced timestamps
|
27 |
transcription_with_timestamps = [
|
@@ -31,8 +41,8 @@ def transcribe(audio_file, model_size):
|
|
31 |
|
32 |
return "\n".join(transcription_with_timestamps)
|
33 |
|
34 |
-
# Streamlit UI
|
35 |
-
st.title("Whisper
|
36 |
st.write("For API use please visit [this space](https://huggingface.co/spaces/Lenylvt/Whisper-API)")
|
37 |
|
38 |
audio_file = st.file_uploader("🎵 Upload Audio or Video", type=['wav', 'mp3', 'ogg', 'mp4', 'avi'])
|
|
|
1 |
import streamlit as st
|
2 |
from faster_whisper import WhisperModel
|
3 |
import logging
|
4 |
+
import tempfile
|
5 |
+
import os
|
6 |
|
7 |
# Configure logging for debugging purposes
|
8 |
logging.basicConfig()
|
|
|
17 |
|
18 |
def transcribe(audio_file, model_size):
|
19 |
# Initialize the Whisper model based on the selected model size
|
20 |
+
device = "cpu" # Use "cpu" for CPU, "cuda" for GPU
|
21 |
+
compute_type = "int8" # Use "int8" for faster inference on both CPU and GPU
|
22 |
|
23 |
model = WhisperModel(model_size, device=device, compute_type=compute_type)
|
24 |
+
|
25 |
+
# Save the uploaded file to a temporary file
|
26 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(audio_file.name)[1]) as tmp:
|
27 |
+
tmp.write(audio_file.getvalue())
|
28 |
+
tmp_path = tmp.name
|
29 |
+
|
30 |
# Transcribe the audio file
|
31 |
+
segments, _ = model.transcribe(tmp_path)
|
32 |
+
|
33 |
+
# Clean up the temporary file
|
34 |
+
os.remove(tmp_path)
|
35 |
|
36 |
# Format and gather transcription with enhanced timestamps
|
37 |
transcription_with_timestamps = [
|
|
|
41 |
|
42 |
return "\n".join(transcription_with_timestamps)
|
43 |
|
44 |
+
# Streamlit UI components
|
45 |
+
st.title("Whisper")
|
46 |
st.write("For API use please visit [this space](https://huggingface.co/spaces/Lenylvt/Whisper-API)")
|
47 |
|
48 |
audio_file = st.file_uploader("🎵 Upload Audio or Video", type=['wav', 'mp3', 'ogg', 'mp4', 'avi'])
|