Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,23 @@ from pydub import AudioSegment
|
|
7 |
from pydub.silence import detect_nonsilent
|
8 |
from waitress import serve
|
9 |
from simple_salesforce import Salesforce
|
|
|
|
|
10 |
|
11 |
app = Flask(__name__)
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Use whisper-small for faster processing and better speed
|
14 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
15 |
asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if device == "cuda" else -1)
|
|
|
7 |
from pydub.silence import detect_nonsilent
|
8 |
from waitress import serve
|
9 |
from simple_salesforce import Salesforce
|
10 |
+
import time
|
11 |
+
from transformers import pipeline
|
12 |
|
13 |
app = Flask(__name__)
|
14 |
|
15 |
+
retry_attempts = 3
|
16 |
+
timeout = 60 # 1 minute timeout for each attempt
|
17 |
+
model = None
|
18 |
+
for attempt in range(retry_attempts):
|
19 |
+
try:
|
20 |
+
model = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if torch.cuda.is_available() else -1, config={"timeout": timeout})
|
21 |
+
print("Model loaded successfully!")
|
22 |
+
break
|
23 |
+
except requests.exceptions.ReadTimeout:
|
24 |
+
print(f"Timeout occurred, retrying attempt {attempt + 1}/{retry_attempts}...")
|
25 |
+
time.sleep(5) # Retry after 5 seconds
|
26 |
+
|
27 |
# Use whisper-small for faster processing and better speed
|
28 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
29 |
asr_model = pipeline("automatic-speech-recognition", model="openai/whisper-small", device=0 if device == "cuda" else -1)
|