Spaces:
Sleeping
Sleeping
cptsubtext
commited on
Commit
·
9f5c443
1
Parent(s):
eecdc1c
fixed version
Browse files- app.py +23 -19
- requirements.txt +56 -2
app.py
CHANGED
@@ -1,11 +1,14 @@
|
|
1 |
import streamlit as st
|
2 |
from stable_whisper import load_model
|
3 |
from stable_whisper import load_hf_whisper
|
|
|
|
|
|
|
4 |
import requests
|
5 |
import os
|
6 |
|
7 |
# Variables
|
8 |
-
valid_api_token = st.secrets["API_TOKEN"]
|
9 |
|
10 |
# Upload audio file
|
11 |
uploaded_file = st.file_uploader("Upload Audio File", type=["mp3", "wav", "mov"])
|
@@ -24,34 +27,35 @@ def transcribe_to_subtitle(audio_bytes, model_name):
|
|
24 |
#speedmodel = load_hf_whisper(model_name)
|
25 |
|
26 |
# Check file size for free tier
|
27 |
-
if use_free_tier and len(audio_bytes) > 0.048 * 2 * 60 * 1024:
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
# Transcribe audio
|
33 |
try:
|
34 |
result = model.transcribe(audio_bytes, verbose=True)
|
|
|
35 |
except Exception as e:
|
36 |
return {"error": f"Error during transcription: {str(e)}"}
|
37 |
-
# else:
|
38 |
-
# try:
|
39 |
-
# result = speedmodel.transcribe(audio_bytes, verbose=True)
|
40 |
-
# except Exception as e:
|
41 |
-
# return {"error": f"Error during transcription: {str(e)}"}
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# Download option
|
49 |
st.success("Transcription successful! Download subtitle file?")
|
50 |
-
|
51 |
-
st.
|
52 |
-
|
53 |
-
st.download_button("Download Subtitle", f, "audio.srt")
|
54 |
-
os.remove("audio.srt") # Remove temporary file
|
55 |
|
56 |
if uploaded_file is not None:
|
57 |
audio_bytes = uploaded_file.read()
|
|
|
1 |
import streamlit as st
|
2 |
from stable_whisper import load_model
|
3 |
from stable_whisper import load_hf_whisper
|
4 |
+
from pydub import AudioSegment
|
5 |
+
import webvtt
|
6 |
+
import pysrt
|
7 |
import requests
|
8 |
import os
|
9 |
|
10 |
# Variables
|
11 |
+
#valid_api_token = st.secrets["API_TOKEN"]
|
12 |
|
13 |
# Upload audio file
|
14 |
uploaded_file = st.file_uploader("Upload Audio File", type=["mp3", "wav", "mov"])
|
|
|
27 |
#speedmodel = load_hf_whisper(model_name)
|
28 |
|
29 |
# Check file size for free tier
|
30 |
+
#if use_free_tier and len(audio_bytes) > 0.048 * 2 * 60 * 1024:
|
31 |
+
# st.error(len(audio_bytes))
|
32 |
+
# st.error("Free tier only supports audio files under 2 minutes")
|
33 |
+
# return
|
34 |
|
35 |
# Transcribe audio
|
36 |
try:
|
37 |
result = model.transcribe(audio_bytes, verbose=True)
|
38 |
+
result.to_srt_vtt('audio.srt')
|
39 |
except Exception as e:
|
40 |
return {"error": f"Error during transcription: {str(e)}"}
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
captions = pysrt.open("audio.srt")
|
43 |
+
for caption in captions:
|
44 |
+
print(caption.start)
|
45 |
+
print(caption.text)
|
46 |
+
print(caption.end)
|
47 |
+
print()
|
48 |
+
|
49 |
+
output = captions.text
|
50 |
+
st.markdown(output, unsafe_allow_html=True)
|
51 |
+
|
52 |
+
|
53 |
|
54 |
# Download option
|
55 |
st.success("Transcription successful! Download subtitle file?")
|
56 |
+
with open("audio.srt", "rb") as f:
|
57 |
+
st.download_button("Download Subtitle in WebVtt Format", f, "audio.srt")
|
58 |
+
os.remove("audio.srt") # Remove temporary file
|
|
|
|
|
59 |
|
60 |
if uploaded_file is not None:
|
61 |
audio_bytes = uploaded_file.read()
|
requirements.txt
CHANGED
@@ -1,2 +1,56 @@
|
|
1 |
-
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==5.3.0
|
2 |
+
attrs==23.2.0
|
3 |
+
blinker==1.8.1
|
4 |
+
cachetools==5.3.3
|
5 |
+
certifi==2024.2.2
|
6 |
+
charset-normalizer==3.3.2
|
7 |
+
click==8.1.7
|
8 |
+
filelock==3.14.0
|
9 |
+
fsspec==2024.3.1
|
10 |
+
gitdb==4.0.11
|
11 |
+
GitPython==3.1.43
|
12 |
+
idna==3.7
|
13 |
+
Jinja2==3.1.3
|
14 |
+
jsonschema==4.22.0
|
15 |
+
jsonschema-specifications==2023.12.1
|
16 |
+
llvmlite==0.42.0
|
17 |
+
markdown-it-py==3.0.0
|
18 |
+
MarkupSafe==2.1.5
|
19 |
+
mdurl==0.1.2
|
20 |
+
more-itertools==10.2.0
|
21 |
+
mpmath==1.3.0
|
22 |
+
networkx==3.3
|
23 |
+
numba==0.59.1
|
24 |
+
numpy==1.26.4
|
25 |
+
openai-whisper==20231117
|
26 |
+
packaging==24.0
|
27 |
+
pandas==2.2.2
|
28 |
+
pillow==10.3.0
|
29 |
+
protobuf==4.25.3
|
30 |
+
pyarrow==16.0.0
|
31 |
+
pydeck==0.9.0
|
32 |
+
Pygments==2.17.2
|
33 |
+
python-dateutil==2.9.0.post0
|
34 |
+
pytz==2024.1
|
35 |
+
referencing==0.35.0
|
36 |
+
regex==2024.4.28
|
37 |
+
requests==2.31.0
|
38 |
+
rich==13.7.1
|
39 |
+
rpds-py==0.18.0
|
40 |
+
six==1.16.0
|
41 |
+
smmap==5.0.1
|
42 |
+
stable-ts==2.16.0
|
43 |
+
streamlit==1.33.0
|
44 |
+
sympy==1.12
|
45 |
+
tenacity==8.2.3
|
46 |
+
tiktoken==0.6.0
|
47 |
+
toml==0.10.2
|
48 |
+
toolz==0.12.1
|
49 |
+
torch==2.2.2
|
50 |
+
torchaudio==2.2.2
|
51 |
+
tornado==6.4
|
52 |
+
tqdm==4.66.2
|
53 |
+
typing_extensions==4.11.0
|
54 |
+
tzdata==2024.1
|
55 |
+
urllib3==2.2.1
|
56 |
+
watchdog==4.0.0
|