File size: 1,227 Bytes
48b5e1d
 
 
 
 
 
 
 
954bd01
 
48b5e1d
 
 
 
 
 
 
 
954bd01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python

import gradio as gr
from urdu_punkt import Urdu
from multi_lingual import MultiLingual
from langdetect import detect, DetectorFactory

DetectorFactory.seed = 42
ur_model = Urdu()
multi_model = MultiLingual()

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")

def punctuate(text: str) -> str:
    if detect(text) == "ur":
        return ur_model.punctuate(text)
    else:
        return multi_model.punctuate(text)

def run():
    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}",
    )
    io.launch(server_name="0.0.0.0", server_port=7860)

if __name__ == "__main__":
    run()