import gradio as gr from aksharamukha import transliterate # A curated list of common scripts. The engine supports over 120+ scripts, # but these cover the major use cases. SCRIPTS = [ "autodetect", "Devanagari", "Gujarati", "Bengali", "Telugu", "Tamil", "Kannada", "Malayalam", "Odia", "Punjabi", "IAST", "HK", "ITRANS", "SLP1", "autodetect", "Urdu" ] def convert_script(source_script, target_script, text): if not text.strip(): return "" try: # If autodetect is chosen, the engine will find the source script automatically if source_script == "autodetect": result = transliterate.process('autodetect', target_script, text) else: result = transliterate.process(source_script, target_script, text) return result except Exception as e: return f"Error during transliteration: {str(e)}" # Define the user interface with gr.Blocks() as demo: gr.Markdown("# 𑀅 Aksharamukha Script Converter") gr.Markdown("A fast, lossless transliteration tool for Indic scripts powered by the official Aksharamukha engine.") with gr.Row(): with gr.Column(): src_dropdown = gr.Dropdown(choices=SCRIPTS, value="autodetect", label="Source Script") input_text = gr.Textbox(lines=8, placeholder="Enter text here (e.g., Sanskrit or Gujarati text)...", label="Input Text") convert_btn = gr.Button("Transliterate", variant="primary") with gr.Column(): tgt_dropdown = gr.Dropdown(choices=SCRIPTS, value="Devanagari", label="Target Script") # removed show_copy_button because the installed gradio version doesn't accept it output_text = gr.Textbox(lines=8, label="Output Text", interactive=False) # Trigger the Python backend when the button is clicked convert_btn.click( fn=convert_script, inputs=[src_dropdown, tgt_dropdown, input_text], outputs=output_text ) # Launch the web server — pass theme here (compatible with older Gradio) demo.launch(theme=gr.themes.Soft())