-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.py
More file actions
33 lines (24 loc) · 961 Bytes
/
api.py
File metadata and controls
33 lines (24 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
from flask import Flask, request, jsonify
from werkzeug.utils import secure_filename
from model import Model
from request import ModelRequest
app = Flask(__name__)
@app.route('/speech_to_text', methods=['POST'])
def speech_to_text():
if 'wav_file' not in request.files:
return jsonify({'success': False, 'error': 'No file part in the request'}), 400
file = request.files['wav_file']
if file.filename == '':
return jsonify({'success': False, 'error': 'No selected file'}), 400
if file:
filename = secure_filename(file.filename)
filepath = os.path.join("/temp_dir", filename)
file.save(filepath)
print(f"Received file: {filename}, saved at: {filepath}")
model_request = ModelRequest(wav_file=filepath)
model = Model()
result = model.inference(model_request)
return jsonify(result)
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')