diff --git a/sziszapangma/integration/asr_processor.py b/sziszapangma/integration/asr_processor.py index bfc26851e59664b7e66564c8ecb3b10120c765c5..f6df63a1c5449e7b210345084bc3a7b9eabc0a23 100644 --- a/sziszapangma/integration/asr_processor.py +++ b/sziszapangma/integration/asr_processor.py @@ -1,5 +1,5 @@ from abc import ABC, abstractmethod -from typing import Any, Dict +from typing import Any, Dict, Optional import requests @@ -16,14 +16,18 @@ class AsrProcessor(ABC): class AsrWebClient(AsrProcessor): _url: str + _auth_token: Optional[str] - def __init__(self, url: str): + def __init__(self, url: str, auth_token: Optional[str]): super(AsrWebClient, self).__init__() self._url = url + self._auth_token = auth_token def call_recognise(self, file_path: str) -> Dict[str, Any]: files = {"file": open(file_path, "rb")} - res = requests.post(self._url, files=files) + headers = dict({'Authorization': f'Bearer {self._auth_token}'}) \ + if self._auth_token is not None else dict() + res = requests.post(self._url, files=files, headers=headers) json_response = res.json() print(json_response) return json_response diff --git a/sziszapangma/integration/base_asr_service/asr_processor.py b/sziszapangma/integration/base_asr_service/asr_processor.py index a35df95ead8e9130a88b0afc65b5c0ae7cba8ed9..6cf478fad1395dec7f8cac4a2f8ddefe6ac79697 100644 --- a/sziszapangma/integration/base_asr_service/asr_processor.py +++ b/sziszapangma/integration/base_asr_service/asr_processor.py @@ -48,10 +48,14 @@ class AsrProcessor(ABC): else: return None + def health_check(self) -> Response: + return jsonify({'status': 'running'}) + def start_processor(self): app = Flask(__name__) auth = HTTPTokenAuth(scheme="Bearer") auth.verify_token(self.is_token_correct) Path(_TEMP_DIRECTORY).mkdir(parents=True, exist_ok=True) app.route("/process_asr", methods=["POST"])(auth.login_required(self.process_request)) + app.route("/health_check", methods=["GET"])(self.health_check) app.run(debug=True, host="0.0.0.0")