Spaces:
Build error
Build error
adding inference
Browse files- app.py +31 -5
- uploads/tmp +0 -0
app.py
CHANGED
@@ -1,9 +1,15 @@
|
|
|
|
1 |
import whisper
|
2 |
from flask import Flask, jsonify, render_template, request, send_file
|
|
|
|
|
3 |
|
4 |
app = Flask(__name__)
|
5 |
|
6 |
STARTING_SIZE = 'small'
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
current_size = STARTING_SIZE
|
@@ -11,11 +17,6 @@ model = whisper.load_model(current_size)
|
|
11 |
model_en = whisper.load_model(f"{current_size}.en")
|
12 |
|
13 |
|
14 |
-
@app.route("/")
|
15 |
-
def index():
|
16 |
-
return "nothing yet to see here"
|
17 |
-
|
18 |
-
|
19 |
def inference(audio_file):
|
20 |
audio = whisper.load_audio(audio_file)
|
21 |
audio = whisper.pad_or_trim(audio)
|
@@ -37,5 +38,30 @@ def inference(audio_file):
|
|
37 |
return segmented_text
|
38 |
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
if __name__ == "__main__":
|
41 |
app.run(host="0.0.0.0", port=7860)
|
1 |
+
import os
|
2 |
import whisper
|
3 |
from flask import Flask, jsonify, render_template, request, send_file
|
4 |
+
from werkzeug.utils import secure_filename
|
5 |
+
|
6 |
|
7 |
app = Flask(__name__)
|
8 |
|
9 |
STARTING_SIZE = 'small'
|
10 |
+
UPLOAD_FOLDER = 'uploads'
|
11 |
+
ALLOWED_EXTENSIONS = {'ogg', 'mp3', 'mp4', 'wav',
|
12 |
+
'flac', 'm4a', 'aac', 'wma', 'webm', 'opus'}
|
13 |
|
14 |
|
15 |
current_size = STARTING_SIZE
|
17 |
model_en = whisper.load_model(f"{current_size}.en")
|
18 |
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
def inference(audio_file):
|
21 |
audio = whisper.load_audio(audio_file)
|
22 |
audio = whisper.pad_or_trim(audio)
|
38 |
return segmented_text
|
39 |
|
40 |
|
41 |
+
def allowed_file(filename):
|
42 |
+
return '.' in filename and \
|
43 |
+
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
|
44 |
+
|
45 |
+
|
46 |
+
@app.route("/", methods=['GET', 'POST'])
|
47 |
+
def index():
|
48 |
+
if request.method == 'POST':
|
49 |
+
# check if the post request has the file part
|
50 |
+
if 'file' not in request.files:
|
51 |
+
return "no file sent!"
|
52 |
+
uploaded_file = request.files['file']
|
53 |
+
if uploaded_file.filename == '':
|
54 |
+
return "no file sent!"
|
55 |
+
if uploaded_file and allowed_file(uploaded_file.filename):
|
56 |
+
filename = secure_filename(uploaded_file.filename)
|
57 |
+
uploaded_file.save(os.path.join(
|
58 |
+
app.config['UPLOAD_FOLDER'], filename))
|
59 |
+
results = inference(os.path.join(
|
60 |
+
app.config['UPLOAD_FOLDER'], filename))
|
61 |
+
return jsonify({"results": results})
|
62 |
+
|
63 |
+
return "nothing yet to see here"
|
64 |
+
|
65 |
+
|
66 |
if __name__ == "__main__":
|
67 |
app.run(host="0.0.0.0", port=7860)
|
uploads/tmp
ADDED
File without changes
|