From 063202d12dc4974767cccb0b0d136582a19a4933 Mon Sep 17 00:00:00 2001 From: odrec Date: Tue, 26 Nov 2024 11:54:45 +0100 Subject: [PATCH] Add Enum Language class to map language abbreviations to full language names to make it easier for users to choose an option from the dropdown. Closes #15 --- app.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 659f1bf..7fea4a1 100644 --- a/app.py +++ b/app.py @@ -9,7 +9,7 @@ from dotenv import load_dotenv from streamlit_quill import st_quill import uuid - +from enum import Enum load_dotenv() @@ -29,6 +29,24 @@ os.makedirs(base_temp_dir, exist_ok=True) +# Define the Language Enum +class Language(Enum): + GERMAN = ("German", "de") + ENGLISH = ("English", "en") + SPANISH = ("Spanish", "es") + FRENCH = ("French", "fr") + ITALIAN = ("Italian", "it") + JAPANESE = ("Japanese", "ja") + DUTCH = ("Dutch", "nl") + PORTUGUESE = ("Portuguese", "pt") + UKRAINIAN = ("Ukrainian", "uk") + CHINESE = ("Chinese", "zh") + + def __init__(self, display_name, code): + self.display_name = display_name + self.code = code + + def upload_file(file, lang, model, min_speakers, max_speakers): files = {'file': file} data = { @@ -183,7 +201,6 @@ def callback_disable_controls(): with st.sidebar: - st.write("Upload a video or audio file or provide a YouTube link to get a transcription.") form_key = "transcription_form" @@ -199,7 +216,14 @@ def callback_disable_controls(): elif input_type == "YouTube Link": st.session_state.youtube_link = st.text_input("Enter YouTube video link") - lang = st.selectbox("Select Language", ["de", "en", "es", "fr", "it", "ja", "nl", "pt", "uk", "zh"]) + # Extract display names and display them in the selectbox + language_display_names = [language.display_name for language in Language] + selected_language_name = st.selectbox("Select Language", language_display_names) + # Retrieve the selected Language Enum member + selected_language = next(language for language in Language if language.display_name == selected_language_name) + # Get the abbreviation code for API calls + lang = selected_language.code + model = st.selectbox("Select Model", ["base", "large-v3"], index=0, help="Base Model: for quick and low effort versions of your audio file " "(balance between accuracy and speed of transcription). "