62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
import os
|
|
|
|
import streamlit as st
|
|
|
|
from utils import get_logger
|
|
from transcription.job_utils import create_job
|
|
from transcription.transcription_helper import transcribe
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
def create_new_task(filepath: str, app_config, overwrite: bool):
|
|
"""
|
|
Create a new task
|
|
:param filepath: path to the audio file
|
|
:param app_config: app configuration
|
|
:param overwrite: overwrite existing task
|
|
:return: None
|
|
"""
|
|
logger.info(f"Creating new task for file {filepath}")
|
|
|
|
if filepath is None:
|
|
st.error("No file uploaded")
|
|
return
|
|
|
|
transcribe(filepath, app_config, blocking=False, overwrite=overwrite)
|
|
|
|
|
|
def render_new_task(container, app_config: dict):
|
|
"""
|
|
Render the new task page
|
|
:param container: container object to place the content in
|
|
:param app_config: app configuration
|
|
:return: None
|
|
"""
|
|
|
|
with container.container():
|
|
st.write("Create a new task")
|
|
# add checkbox for overwrite
|
|
with st.form(key="new_task_form", clear_on_submit=True):
|
|
overwrite = st.checkbox("Overwrite existing task", value=False, key="overwrite")
|
|
uploaded_file = st.file_uploader("Audio File", type=["wav", "mp3", "flac", "ogg"], key="audio_file")
|
|
file_path = None
|
|
|
|
if uploaded_file is not None:
|
|
# save files to upload directory
|
|
upload_directory = app_config["data"]["upload_directory"]
|
|
|
|
# create the upload directory if it does not exist
|
|
if not os.path.exists(upload_directory):
|
|
logger.info(f"Creating upload directory {upload_directory}")
|
|
os.makedirs(upload_directory)
|
|
|
|
logger.info(f"Saving file {uploaded_file.name} to {upload_directory}")
|
|
file_path = f"{upload_directory}/{uploaded_file.name}"
|
|
with open(file_path, "wb") as file:
|
|
file.write(uploaded_file.getbuffer())
|
|
|
|
st.success(f"File saved to {file_path}")
|
|
|
|
st.form_submit_button("Create Task", on_click=create_new_task, args=(file_path, app_config, overwrite))
|