Akseltinfat's picture
Update app.py
1f5c327 verified
raw
history blame
2.66 kB
import gradio as gr
# Tifinagh to Latin conversion map
tifinagh_to_latin_map = {
'ⴰ': 'a', 'ⴱ': 'b', 'ⵛ': 'c', 'ⴷ': 'd', 'ⴻ': 'e', 'ⴼ': 'f', 'ⴳ': 'g', 'ⵀ': 'h',
'ⵉ': 'i', 'ⵊ': 'j', 'ⴽ': 'k', 'ⵍ': 'l', 'ⵎ': 'm', 'ⵏ': 'n', 'ⵓ': 'u', 'ⵒ': 'p',
'ⵇ': 'q', 'ⵔ': 'r', 'ⵙ': 's', 'ⵜ': 't', 'ⵡ': 'w', 'ⵅ': 'x', 'ⵢ': 'y',
'ⵣ': 'z', 'ⴽⵯ': 'kʷ', 'ⵯ': 'ʷ', 'ⵇⵯ': 'qʷ', 'ⵖ': 'ɣ', 'ⵄ': 'ɛ', 'ⵥ': 'ẓ',
'ⵕ': 'ṛ', 'ⵚ': 'ṣ', 'ⵃ': 'ḥ', 'ⵟ': 'ṭ', 'ⴹ': 'ḍ'
}
# Latin to Tifinagh conversion map (support for both uppercase and lowercase)
latin_to_tifinagh_map = {
'A': 'ⴰ', 'B': 'ⴱ', 'C': 'ⵛ', 'D': 'ⴷ', 'E': 'ⴻ', 'F': 'ⴼ', 'G': 'ⴳ', 'H': 'ⵀ',
'I': 'ⵉ', 'J': 'ⵊ', 'K': 'ⴽ', 'L': 'ⵍ', 'M': 'ⵎ', 'N': 'ⵏ', 'U': 'ⵓ', 'P': 'ⵒ',
'Q': 'ⵇ', 'R': 'ⵔ', 'S': 'ⵙ', 'T': 'ⵜ', 'V': 'ⴼ', 'W': 'ⵡ', 'X': 'ⵅ', 'Y': 'ⵢ',
'Z': 'ⵣ', 'kʷ': 'ⴽⵯ', 'ʷ': 'ⵯ', 'qʷ': 'ⵇⵯ', 'ɣ': 'ⵖ', 'ɛ': 'ⵄ', 'ẓ': 'ⵥ',
'ṛ': 'ⵕ', 'ṣ': 'ⵚ', 'ḥ': 'ⵃ', 'ṭ': 'ⵟ',
'a': 'ⴰ', 'b': 'ⴱ', 'c': 'ⵛ', 'd': 'ⴷ', 'e': 'ⴻ', 'f': 'ⴼ', 'g': 'ⴳ', 'h': 'ⵀ',
'i': 'ⵉ', 'j': 'ⵊ', 'k': 'ⴽ', 'l': 'ⵍ', 'm': 'ⵎ', 'n': 'ⵏ', 'o': 'ⵓ', 'p': 'ⵒ',
'q': 'ⵇ', 'r': 'ⵔ', 's': 'ⵙ', 't': 'ⵜ', 'v': 'ⴼ', 'w': 'ⵡ', 'x': 'ⵅ', 'y': 'ⵢ',
'z': 'ⵣ','ḍ':'ⴹ','Ḍ':'ⴹ'
}
def convert_text(input_text, conversion_type):
if conversion_type == 'Tifinagh to Latin':
return ''.join(tifinagh_to_latin_map.get(char, char) for char in input_text)
elif conversion_type == 'Latin to Tifinagh':
return ''.join(latin_to_tifinagh_map.get(char, char) for char in input_text)
return input_text
# Gradio Interface with updated theme, centered description, and frame
iface = gr.Interface(
fn=convert_text,
inputs=[
gr.Textbox(label="Enter Text", placeholder="Type text here..."),
gr.Radio(["Tifinagh to Latin", "Latin to Tifinagh"], label="From")
],
outputs=gr.Textbox(label="Converted Text", interactive=True),
live=True,
title="Tifinagh Converter",
description="<center>Convert text between Tifinagh and Latin scripts.</center>", # Centering the description
theme=gr.themes.Glass(), # Updated theme
layout="vertical", # Ensures a clean, vertically stacked layout
elem_id="main-frame", # Optional, allows targeting with custom CSS if needed
css=".gradio-container { border: 2px solid #000; padding: 20px; border-radius: 10px; }" # Adding a border around the interface
)
iface.launch()