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