import os
import subprocess
import gradio as gr


def run_mokuro(folder_path):
    """Runs the mokuro command on the given folder path.

    Args:
        folder_path (str): The path to the folder to run mokuro on.

    Returns:
        None.
    """
    command = f"""mokuro "{folder_path}" --as_one_file --disable_confirmation"""
    subprocess.run(command, stdout=subprocess.PIPE, shell=True)


def get_folder_paths():
    """Gets the list of all folder paths in the current directory.

    Returns:
        List[str]: The list of all folder paths in the current directory.
    """
    folder_paths = []
    for entry in os.scandir("/content"):
        if entry.is_dir():
            folder_paths.append(entry.path)
    return folder_paths


folder_paths = get_folder_paths()
folder_path_input = gr.inputs.Dropdown(choices=folder_paths, label="Select Folder Path")
output_text = gr.outputs.Textbox(label="Output")


iface = gr.Interface(fn=run_mokuro, inputs=folder_path_input, outputs=output_text, title="Mokuro Execution")
iface.launch(share=True, inline=True)
