punctcap / main.py
mturan's picture
Add application file
48b5e1d
raw
history blame
1.21 kB
#!/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)