Spaces:
Sleeping
Sleeping
File size: 1,212 Bytes
48b5e1d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#!/usr/bin/env python
import gradio as gr
from fastapi import FastAPI
from urdu_punkt import Urdu
from multi_lingual import MultiLingual
from langdetect import detect, DetectorFactory
CUSTOM_PATH = "/punctuate"
DetectorFactory.seed = 42
app = FastAPI()
nemo_model = Urdu()
multi_model = MultiLingual()
def punctuate(text: str) -> str:
if detect(text) == "ur":
return nemo_model.punctuate(text)
else:
return multi_model.punctuate(text)
title = "SELMA H2020 — Multilingual Punctuation & Casing Prediction"
description = "Supported languages are: Amharic, Bengali, German, English, Spanish, French, Hindi, Italian, Latvian, Pashto, Portuguese, Russian, Tamil and Urdu."
article = "<p style='text-align: center'><a href='https://selma-project.eu' target='_blank'>SELMA-H2020</a></p>"
text_input = gr.Textbox(label="Enter some text")
result_output = gr.Textbox(label="Result")
io = gr.Interface(
fn=punctuate,
title=title,
description=description,
article=article,
theme=gr.themes.Soft(),
inputs=text_input,
outputs=result_output,
allow_flagging="never",
css="footer {visibility: hidden}",
)
app = gr.mount_gradio_app(app, io, path=CUSTOM_PATH)
|