Spaces:
Build error
Build error
Download app.py from vivekharry/ancient_script_translator: direct link, hf CLI and curl.
- Browser
- Download file 3.22 kB
-
https://huggingface.co/spaces/vivekharry/ancient_script_translator/resolve/main/app.py
- Command line
-
hf download hf://spaces/vivekharry/ancient_script_translator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/vivekharry/ancient_script_translator/resolve/main/app.py
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() |