Spaces:
Runtime error
Runtime error
| import os | |
| import gradio as gr | |
| from transformers import pipeline | |
| # -------------------------------------------------- | |
| # Optional: private model support | |
| # -------------------------------------------------- | |
| HF_TOKEN = os.getenv("HF_TOKEN", None) | |
| MODEL_ID = "Neurai/Persian_G2P" | |
| # Example private model: | |
| # MODEL_ID = "username/private-model" | |
| # -------------------------------------------------- | |
| # Load pipeline | |
| # -------------------------------------------------- | |
| pipe = pipeline( | |
| "summarization", | |
| model=MODEL_ID, | |
| token=HF_TOKEN, # works for private models | |
| device_map="auto" # GPU if available | |
| ) | |
| # -------------------------------------------------- | |
| # Inference function | |
| # -------------------------------------------------- | |
| def generate(text): | |
| output = pipe(text) | |
| return output[0]['summary_text'] | |
| # -------------------------------------------------- | |
| # Gradio UI | |
| # -------------------------------------------------- | |
| demo = gr.Interface( | |
| fn=generate, | |
| inputs=[ | |
| gr.Textbox(lines=4, label="Grapheme",value="نه بابا چی میگی این عدده نه هزار رو پانصد و بیست و نه هست"), | |
| ], | |
| outputs=gr.Textbox(lines=4, label="Phoneme"), | |
| title="Neura Persian G2P", | |
| description="Neura Persian Grapheme to Phenoneme" | |
| ) | |
| demo.launch() | |