Skip to content

Commit

Permalink
Merge pull request #106 from dishantsethi/main
Browse files Browse the repository at this point in the history
add invalid JSON log
  • Loading branch information
dishantsethi authored Aug 20, 2024
2 parents 6ecde79 + c54bea7 commit 20d9d79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/test_diarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_willis_diarize_function_success(
self, mock_file_path, mock_json, mock_api_res, mock_decoded_res, caplog
):
mock_file_path.return_value = True
mock_json.return_value = {}
mock_json.return_value = {"Correct Transcription"}
mock_api_res.return_value = {
"status_code": 200,
"data": "Encoded Response",
Expand Down
11 changes: 8 additions & 3 deletions willisapi_client/services/diarize/diarize_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
import os
import gzip
import base64
from willisapi_client.logging_setup import logger as logger


class DiarizeUtils:
def is_valid_file_path(file_path: str):
return file_path.endswith(".json") and os.path.exists(file_path)

def read_json_file(file_path: str):
with open(file_path) as f:
json_data = json.load(f)
data = dict(json_data=json_data)
data = None
try:
with open(file_path) as f:
json_data = json.load(f)
data = dict(json_data=json_data)
except json.decoder.JSONDecodeError:
logger.info("No data found in the file or JSON is invalid.")
return data

def decode_response(encoded_response):
Expand Down
3 changes: 3 additions & 0 deletions willisapi_client/services/diarize/willisdiarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def willis_diarize(key: str, file_path: str, **kwargs):

data = DiarizeUtils.read_json_file(file_path)

if not data:
return corrected_transcript

response = DiarizeUtils.request_diarize(url, data, headers, try_number=1)
if response["status_code"] != HTTPStatus.OK:
logger.info(response["message"])
Expand Down

0 comments on commit 20d9d79

Please sign in to comment.