Spaces:
Sleeping
Sleeping
| import os | |
| import re | |
| import unicodedata | |
| import gradio as gr | |
| from cached_path import cached_path | |
| from deep_phonemizer.phonemizer import Phonemizer | |
| from g2p import make_g2p | |
| from huggingface_hub import login | |
| login(token=os.getenv("login")) | |
| normalizer = make_g2p("str", "str-equiv") | |
| checkpoint_path = cached_path("hf://lobot-penac/g2p/model_step_420k.pt") | |
| phonemizer = Phonemizer.from_checkpoint(checkpoint_path) | |
| # Your custom G2P function | |
| def g2p_function(text): | |
| text = unicodedata.normalize("NFC", normalizer(text).output_string) | |
| texts = text.split() | |
| result = phonemizer.phonemise_list(texts, lang="str") | |
| return " ".join(result.phonemes) | |
| # Gradio interface | |
| with gr.Blocks(theme=gr.themes.Default(font=[gr.themes.GoogleFont("Tinos"), "Arial", "sans-serif"])) as demo: | |
| gr.Markdown(""" | |
| <style> | |
| body, textarea, input { | |
| font-size: 24px !important; | |
| } | |
| </style> | |
| """) | |
| gr.Markdown("# G2P Converter\nEnter SENĆOŦEN text and see its phonemic transcription.") | |
| input_text = gr.Textbox(lines=2, label="SENĆOŦEN Orthography", placeholder="Enter text here...") | |
| output_text = gr.Textbox(label="Phonemes") | |
| input_text.change(fn=g2p_function, inputs=input_text, outputs=output_text) | |
| # Run the app | |
| if __name__ == "__main__": | |
| demo.launch(share=True) | |