vivekharry's picture
Create app.py
0746322 verified
Raw History Blame Contribute Delete
3.22 kB
import gradio as gr
# Mapping English to various ancient-style Unicode characters
HIEROGLYPHS = {
'a': 'π“€€', 'b': '𓃀', 'c': 'π“Ž‘', 'd': 'π“‚§', 'e': '𓇋',
'f': '𓆑', 'g': 'π“ŽΌ', 'h': '𓉔', 'i': '𓇋', 'j': '𓆓',
'k': 'π“Ž‘', 'l': '𓃭', 'm': 'π“…“', 'n': 'π“ˆ–', 'o': '𓂝',
'p': 'π“Šͺ', 'q': 'π“˜', 'r': 'π“‚‹', 's': 'π“‹΄', 't': '𓏏',
'u': 'π“…±', 'v': '𓆑', 'w': 'π“…±', 'x': 'π“Ž‘π“‹΄', 'y': '𓇋',
'z': 'π“Šƒ', ' ': ' '
}
RUNES = {
'a': 'ᚨ', 'b': 'α›’', 'c': 'ᚲ', 'd': 'α›ž', 'e': 'α›–',
'f': 'ᚠ', 'g': 'ᚷ', 'h': 'ᚺ', 'i': 'ᛁ', 'j': 'ᛃ',
'k': 'ᚲ', 'l': 'α›š', 'm': 'α›—', 'n': 'ᚾ', 'o': 'α›Ÿ',
'p': 'α›ˆ', 'q': 'ᚲᚹ', 'r': 'ᚱ', 's': 'α›Š', 't': 'ᛏ',
'u': 'ᚒ', 'v': 'ᚹ', 'w': 'ᚹ', 'x': 'αš²α›Š', 'y': 'ᛃ',
'z': 'ᛉ', ' ': ' α›« '
}
CUNEIFORM = {
'a': 'π’€€', 'b': '𒁀', 'c': 'π’„€', 'd': '𒁲', 'e': 'π’‚Š',
'f': 'π’„«', 'g': 'π’‚΅', 'h': 'π’„©', 'i': 'π’„Ώ', 'j': 'π’‹›',
'k': 'π’† ', 'l': 'π’‡·', 'm': 'π’ˆ ', 'n': 'π’ˆΎ', 'o': 'π’Œ‹',
'p': 'π’‰Ί', 'q': 'π’†ͺ', 'r': 'π’Š', 's': 'π’Š“', 't': 'π’‹—',
'u': 'π’Œ‘', 'v': '𒁀', 'w': 'π’‰Ώ', 'x': 'π’„­', 'y': 'π’…€',
'z': '𒍣', ' ': ' '
}
SCRIPTS = {
"Egyptian Hieroglyphs π“‚€": HIEROGLYPHS,
"Elder Futhark Runes ᚠ": RUNES,
"Sumerian Cuneiform π’€€": CUNEIFORM,
}
SCRIPT_INFO = {
"Egyptian Hieroglyphs π“‚€": "Egyptian hieroglyphs were used from ~3200 BCE to 400 CE. They are one of the earliest writing systems, combining logographic and alphabetic elements.",
"Elder Futhark Runes ᚠ": "Elder Futhark runes were used by Germanic peoples from the 2nd to 8th centuries CE. Each rune had a name and magical significance.",
"Sumerian Cuneiform π’€€": "Cuneiform is one of the earliest writing systems, developed in Sumer around 3400 BCE. It was written on clay tablets with a reed stylus.",
}
def translate(text, script_name):
if not text:
return "", ""
script = SCRIPTS[script_name]
translated = []
for char in text.lower():
translated.append(script.get(char, char))
result = ''.join(translated)
# Build character breakdown
breakdown = "### Character Breakdown\n\n"
breakdown += "| Latin | Ancient | \n|---|---|\n"
seen = set()
for char in text.lower():
if char not in seen and char in script:
seen.add(char)
breakdown += f"| {char.upper()} | {script[char]} |\n"
info = f"### About {script_name}\n\n{SCRIPT_INFO[script_name]}"
return result, f"{info}\n\n{breakdown}"
demo = gr.Interface(
fn=translate,
inputs=[
gr.Textbox(label="Enter English Text", lines=3,
placeholder="Type something like 'Hello World'..."),
gr.Radio(list(SCRIPTS.keys()), value="Egyptian Hieroglyphs π“‚€",
label="Choose Ancient Script"),
],
outputs=[
gr.Textbox(label="Ancient Translation", lines=3),
gr.Markdown(label="Details"),
],
title="πŸ“œ Ancient Script Translator",
description="Convert modern English into ancient writing systems.",
theme=gr.themes.Soft(),
)
if __name__ == "__main__":
demo.launch()