import gradio as gr | |
from ai4bharat.transliteration import XlitEngine | |
# Function for transliteration | |
def transliterate_to_kannada(user_input): | |
# Create an instance of the transliteration engine | |
e = XlitEngine(src_script_type="en", beam_width=5, rescore=False) | |
# Perform transliteration | |
out = e.translit_sentence(user_input, lang_code="kn") | |
return out | |
# Set up the Gradio interface | |
with gr.Blocks() as demo: | |
gr.Markdown(""" | |
# English to Kannada Transliteration | |
This tool allows you to convert English sentences into Kannada transliterations. | |
**How to use:** | |
1. Enter a sentence in English in the text box. | |
2. Click "Transliterate" to see the Kannada output. | |
""") | |
# Create input field for user sentence | |
user_input = gr.Textbox(label="Enter the sentence in English:", placeholder="e.g., Hello, how are you?") | |
# Output area for transliterated text | |
transliterated_output = gr.Textbox(label="Transliterated Output (Kannada):", placeholder="Result will be shown here") | |
# Button to trigger the transliteration | |
submit_button = gr.Button("Transliterate") | |
# Define the button action | |
submit_button.click(fn=transliterate_to_kannada, inputs=user_input, outputs=transliterated_output) | |
# Launch the Gradio interface | |
demo.launch(share=True, inbrowser=True) | |