Download main.py from SortStorm/Ollid: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/SortStorm/Ollid/resolve/main/main.py
- Command line
-
hf download hf://spaces/SortStorm/Ollid/main.py
-
curl -L -o main.py https://huggingface.co/spaces/SortStorm/Ollid/resolve/main/main.py
1.31 kB
| from flask import Flask, request | |
| from flask_restful import Api, Resource | |
| from flask_cors import CORS | |
| from waitress import serve | |
| import whisper | |
| import librosa | |
| import numpy as np | |
| import os | |
| os.environ['TRANSFORMERS_CACHE'] = '/.cache/huggingface/hub' | |
| os.environ['SENTENCE_TRANSFORMERS_HOME'] = './.cache' | |
| app = Flask(__name__) | |
| CORS(app) | |
| api = Api() | |
| class Main(Resource): | |
| def post(self): | |
| print(request) | |
| file = request.files["file"] | |
| if file: | |
| print(file) | |
| audio, sr = librosa.load(file.stream) | |
| print('NO ERROR 1') | |
| audio_array = np.array(audio, dtype=np.float32) | |
| print('NO ERROR 2') | |
| model = whisper.load_model("medium") | |
| print('NO ERROR 3') | |
| result = model.transcribe(audio_array, fp16=False) | |
| print('NO ERROR 4') | |
| captions = [[(int)(caption["start"] * 1000), (int)(caption["end"] * 1000), caption["text"]] for caption in | |
| result['segments']] | |
| print(f'Отвечаю: {captions}') | |
| return {'status': 'ok', 'captions': captions} | |
| def get(self): | |
| return {'status': 'ok', 'type': 'get'} | |
| api.add_resource(Main, "/") | |
| api.init_app(app) | |
| if __name__ == "__main__": | |
| # serve(app, port=5000, host="0.0.0.0") | |
| app.run(debug=True, port=7860, host="0.0.0.0") | |