Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for fallback_language and True and False options #42

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/mediacatch_s2t/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ def main() -> None:
parser.add_argument("api_key", type=str, help="MediaCatch API key.")
parser.add_argument("file", type=str, help="A media file.")
parser.add_argument("--quota", type=str, default=None, help="The quota to bill usage to. Defaults to None.")
parser.add_argument("--fallback_language", type=str, default=None, help="Overrides the language to transcribe in if language identification fails. If None, uses the default language of the quota.")
parser.add_argument("--fallback_language", type=str, default=True, help="Overrides the language to transcribe in if language identification fails. If True or None, it uses the default language of the quota. If False, the quota default language is ignored.")
args = parser.parse_args()

if args.fallback_language in ['True', 'False', 'None']:
args.fallback_language = eval(args.fallback_language)

console = Console()
with console.status(
"[bold green]Uploading file to MediaCatch..."):
Expand Down
5 changes: 3 additions & 2 deletions src/mediacatch_s2t/uploader.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
from pathlib import Path
from typing import Optional, Generator
from typing import Optional, Generator, Union

from mediacatch_s2t import (
URL,
Expand Down Expand Up @@ -203,13 +203,14 @@ def _is_response_successful(response: requests.Response) -> bool:
"""
return 200 <= response.status_code < 300

def upload_and_get_transcription(file: str, api_key: str, quota: Optional[str] = None, fallback_language: Optional[str] = None) -> dict[str, str]:
def upload_and_get_transcription(file: str, api_key: str, quota: Optional[str] = None, fallback_language: Optional[Union[str, bool]] = None) -> dict[str, str]:
"""Uploads a file and returns its transcription.

Args:
file (str): The path to the file to be uploaded.
api_key (str): The API key for authentication.
quota (str | None): The quota to bill transcription hours from. Use None if user only has 1 quota.
fallback_language (str | bool | None): Overrides the language to transcribe in if language identification fails. If True or None, it uses the default language of the quota. If False, the quota default language is ignored.

Returns:
dict[str, str]: A dictionary containing the transcription or error message.
Expand Down
Loading