micahg's picture
Initial file upload
609216a
raw
history blame
1.64 kB
import gradio as gr
from functions import convert_script
from config import scripts
DEFAULT_INPUT_SCRIPT = list(scripts.keys())[0]
DEFAULT_OUTPUT_SCRIPT = list(scripts.keys())[1]
def process_text(input_script, output_script, input_text, uploaded_file=None):
if uploaded_file is not None:
input_text = uploaded_file.decode("utf-8")
output_text = convert_script(scripts[input_script], scripts[output_script], input_text)
output_filename = "output.txt"
with open(output_filename, "w") as file:
file.write(output_text)
return output_text, output_filename
with gr.Blocks(title="Rohingya Script Converter") as page:
gr.Markdown("## Rohingya Script Converter")
with gr.Row():
input_script = gr.Dropdown(label="Choose the input script:", choices=scripts.keys(), value=DEFAULT_INPUT_SCRIPT)
output_script = gr.Dropdown(label="Choose the output script:", choices=scripts.keys(), value=DEFAULT_OUTPUT_SCRIPT)
with gr.Row():
input_text = gr.Textbox(label="Input Text", placeholder="Enter text here or upload a file", lines=5)
output_text = gr.Textbox(label="Output Text", placeholder="Converted text will appear here", lines=5, interactive=False)
with gr.Row():
input_file = gr.File(label="Upload Text File", file_count="single", type="binary")
download_link = gr.File(label="Download Converted File")
gr.Button("Convert").click(
process_text,
inputs=[input_script, output_script, input_text, input_file],
outputs=[output_text, download_link]
)
page.launch(share=True)