Spaces:
Sleeping
Sleeping
cptsubtext
commited on
Commit
·
a703b74
1
Parent(s):
cd87ff7
use faster model if api token is provided
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from stable_whisper import load_model
|
|
|
3 |
import requests
|
4 |
import os
|
5 |
|
@@ -20,6 +21,7 @@ def transcribe_to_subtitle(audio_bytes, model_name):
|
|
20 |
"""Transcribe audio to subtitle using OpenAI Whisper"""
|
21 |
# Load model based on selection
|
22 |
model = load_model(model_name)
|
|
|
23 |
|
24 |
# Check file size for free tier
|
25 |
if use_free_tier and len(audio_bytes) > 2 * 60 * 1024:
|
@@ -27,10 +29,16 @@ def transcribe_to_subtitle(audio_bytes, model_name):
|
|
27 |
return
|
28 |
|
29 |
# Transcribe audio
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
# Generate subtitle file
|
36 |
subtitle_text = result.text
|
|
|
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 |
|
|
|
21 |
"""Transcribe audio to subtitle using OpenAI Whisper"""
|
22 |
# Load model based on selection
|
23 |
model = load_model(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) > 2 * 60 * 1024:
|
|
|
29 |
return
|
30 |
|
31 |
# Transcribe audio
|
32 |
+
if use_free_tier and not api_token:
|
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 |
# Generate subtitle file
|
44 |
subtitle_text = result.text
|