Spaces:
Build error
Build error
using gunicorn
Browse files
app.py
CHANGED
@@ -1,7 +1,15 @@
|
|
|
|
|
|
1 |
import os
|
2 |
import whisper
|
3 |
from flask import Flask, jsonify, request
|
4 |
from werkzeug.utils import secure_filename
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
STARTING_SIZE = 'small'
|
7 |
UPLOAD_FOLDER = 'uploads'
|
@@ -9,6 +17,7 @@ ALLOWED_EXTENSIONS = {'ogg', 'mp3', 'mp4', 'wav',
|
|
9 |
'flac', 'm4a', 'aac', 'wma', 'webm', 'opus'}
|
10 |
normal_size = STARTING_SIZE
|
11 |
small_size = 'base'
|
|
|
12 |
|
13 |
app = Flask(__name__)
|
14 |
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
@@ -18,6 +27,22 @@ model_en = whisper.load_model(f"{normal_size}.en")
|
|
18 |
model_small = whisper.load_model(small_size)
|
19 |
model_small_en = whisper.load_model(f"{small_size}.en")
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
def inference(audio_file, model=model, model_en=model_en):
|
23 |
audio = whisper.load_audio(audio_file)
|
@@ -84,4 +109,14 @@ def small():
|
|
84 |
|
85 |
|
86 |
if __name__ == "__main__":
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from asyncio.log import logger
|
2 |
+
import logging
|
3 |
import os
|
4 |
import whisper
|
5 |
from flask import Flask, jsonify, request
|
6 |
from werkzeug.utils import secure_filename
|
7 |
+
try:
|
8 |
+
import gunicorn.app.base
|
9 |
+
gunicorn = True
|
10 |
+
except ImportError:
|
11 |
+
logging.exception("gunicorn not installed")
|
12 |
+
gunicorn = False
|
13 |
|
14 |
STARTING_SIZE = 'small'
|
15 |
UPLOAD_FOLDER = 'uploads'
|
|
|
17 |
'flac', 'm4a', 'aac', 'wma', 'webm', 'opus'}
|
18 |
normal_size = STARTING_SIZE
|
19 |
small_size = 'base'
|
20 |
+
PORT = 7860
|
21 |
|
22 |
app = Flask(__name__)
|
23 |
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
|
|
27 |
model_small = whisper.load_model(small_size)
|
28 |
model_small_en = whisper.load_model(f"{small_size}.en")
|
29 |
|
30 |
+
if gunicorn:
|
31 |
+
class StandaloneApplication(gunicorn.app.base.BaseApplication):
|
32 |
+
def __init__(self, app, options=None):
|
33 |
+
self.options = options or {}
|
34 |
+
self.application = app
|
35 |
+
super().__init__()
|
36 |
+
|
37 |
+
def load_config(self):
|
38 |
+
config = {key: value for key, value in self.options.items()
|
39 |
+
if key in self.cfg.settings and value is not None}
|
40 |
+
for key, value in config.items():
|
41 |
+
self.cfg.set(key.lower(), value)
|
42 |
+
|
43 |
+
def load(self):
|
44 |
+
return self.application
|
45 |
+
|
46 |
|
47 |
def inference(audio_file, model=model, model_en=model_en):
|
48 |
audio = whisper.load_audio(audio_file)
|
|
|
109 |
|
110 |
|
111 |
if __name__ == "__main__":
|
112 |
+
|
113 |
+
options = {
|
114 |
+
'bind': f'0.0.0.0:{PORT}',
|
115 |
+
# 'workers': 4,
|
116 |
+
'timeout': 600,
|
117 |
+
}
|
118 |
+
try:
|
119 |
+
StandaloneApplication(app, options).run()
|
120 |
+
except:
|
121 |
+
logging.exception("Error starting server, backing off to debug mode")
|
122 |
+
app.run(host="0.0.0.0", port=PORT)
|