Spaces:
Sleeping
Sleeping
update for gradio latest version
Browse files
app.py
CHANGED
@@ -21,27 +21,6 @@ categories = {
|
|
21 |
"society": "Setšhaba"
|
22 |
}
|
23 |
|
24 |
-
with gr.Row():
|
25 |
-
gr.Column()
|
26 |
-
gr.Column(gr.Image(value="logo_transparent_small.png", elem_id="logo", label=None))
|
27 |
-
gr.Column()
|
28 |
-
|
29 |
-
description = """
|
30 |
-
<p style='text-align: center;'>
|
31 |
-
Setswana News Classification
|
32 |
-
</p>
|
33 |
-
<p>
|
34 |
-
This space provides a classification service for news in Setswana.
|
35 |
-
</p>
|
36 |
-
"""
|
37 |
-
|
38 |
-
article = """
|
39 |
-
<div style='text-align: center;'>
|
40 |
-
<a href='https://github.com/dsfsi/PuoBERTa-News' target='_blank'>GitHub</a> |
|
41 |
-
<a href='https://docs.google.com/forms/d/e/1FAIpQLSf7S36dyAUPx2egmXbFpnTBuzoRulhL5Elu-N1eoMhaO7v10w/viewform' target='_blank'>Feedback Form</a>
|
42 |
-
</div>
|
43 |
-
"""
|
44 |
-
|
45 |
def prediction(news):
|
46 |
classifier = pipeline("text-classification", tokenizer=tokenizer, model=model, return_all_scores=True)
|
47 |
preds = classifier(news)
|
@@ -68,52 +47,71 @@ def file_prediction(file):
|
|
68 |
|
69 |
return results
|
70 |
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
)
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
""
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
"""
|
109 |
-
|
110 |
-
|
111 |
-
<div style='text-align: center;'>
|
112 |
-
|
113 |
-
</div>
|
114 |
-
"""
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
"society": "Setšhaba"
|
22 |
}
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def prediction(news):
|
25 |
classifier = pipeline("text-classification", tokenizer=tokenizer, model=model, return_all_scores=True)
|
26 |
preds = classifier(news)
|
|
|
47 |
|
48 |
return results
|
49 |
|
50 |
+
with gr.Blocks() as demo:
|
51 |
+
gr.Markdown("""
|
52 |
+
<div style='text-align: center;'>
|
53 |
+
<img src='file/logo_transparent_small.png' alt='Logo' width='150'/>
|
54 |
+
</div>
|
55 |
+
""")
|
56 |
+
|
57 |
+
gr.Markdown("""
|
58 |
+
<h1 style='text-align: center;'>Setswana News Classification</h1>
|
59 |
+
<p style='text-align: center;'>This space provides a classification service for news in Setswana.</p>
|
60 |
+
""")
|
61 |
+
|
62 |
+
with gr.Tabs():
|
63 |
+
with gr.Tab("Text Input"):
|
64 |
+
gr.Markdown(f"""
|
65 |
+
Enter Setswana news article to see the category of the news. <br>
|
66 |
+
For this classification, the <a href='{MODEL_URL}' target='_blank'>PuoBERTa-News</a> model was used.
|
67 |
+
""")
|
68 |
+
inp_text = gr.Textbox(lines=10, label="Paste some Setswana news here")
|
69 |
+
output_label = gr.Label(num_top_classes=5, label="News categories probabilities")
|
70 |
+
translate_button = gr.Button("Classify")
|
71 |
+
translate_button.click(prediction, inputs=inp_text, outputs=output_label)
|
72 |
+
|
73 |
+
with gr.Tab("File Upload"):
|
74 |
+
gr.Markdown("""
|
75 |
+
Upload a text or CSV file with Setswana news articles. The first column in the CSV should contain the news text.
|
76 |
+
""")
|
77 |
+
file_input = gr.File(label="Upload text or CSV file")
|
78 |
+
file_output = gr.Dataframe(headers=["News Text", "Category Predictions"], label="Predictions from file")
|
79 |
+
file_button = gr.Button("Classify File")
|
80 |
+
file_button.click(file_prediction, inputs=file_input, outputs=file_output)
|
81 |
+
|
82 |
+
gr.Markdown("""
|
83 |
+
<div style='text-align: center;'>
|
84 |
+
<a href='https://github.com/dsfsi/PuoBERTa-News' target='_blank'>GitHub</a> |
|
85 |
+
<a href='https://docs.google.com/forms/d/e/1FAIpQLSf7S36dyAUPx2egmXbFpnTBuzoRulhL5Elu-N1eoMhaO7v10w/viewform' target='_blank'>Feedback Form</a>
|
86 |
+
</div>
|
87 |
+
""")
|
88 |
+
|
89 |
+
gr.Markdown("""
|
90 |
+
<div style='text-align: center;'>
|
91 |
+
Authors: Vukosi Marivate and Moseli Mots'Oehli and Valencia Wagner and Richard Lastrucci and Isheanesu Dzingirai
|
92 |
+
</div>
|
93 |
+
""")
|
94 |
+
|
95 |
+
gr.Markdown("""
|
96 |
+
<pre style="text-align: left; white-space: pre-wrap;">
|
97 |
+
@inproceedings{marivate2023puoberta,
|
98 |
+
title = {PuoBERTa: Training and evaluation of a curated language model for Setswana},
|
99 |
+
author = {Vukosi Marivate and Moseli Mots'Oehli and Valencia Wagner and Richard Lastrucci and Isheanesu Dzingirai},
|
100 |
+
year = {2023},
|
101 |
+
booktitle= {Artificial Intelligence Research. SACAIR 2023. Communications in Computer and Information Science},
|
102 |
+
url= {https://link.springer.com/chapter/10.1007/978-3-031-49002-6_17},
|
103 |
+
keywords = {NLP},
|
104 |
+
preprint_url = {https://arxiv.org/abs/2310.09141},
|
105 |
+
dataset_url = {https://github.com/dsfsi/PuoBERTa},
|
106 |
+
software_url = {https://huggingface.co/dsfsi/PuoBERTa}
|
107 |
+
}
|
108 |
+
</pre>
|
109 |
+
""")
|
110 |
+
|
111 |
+
gr.Markdown("""
|
112 |
+
<div style='text-align: center;'>
|
113 |
+
DOI: <a href="https://doi.org/10.1007/978-3-031-49002-6_17" target="_blank">10.1007/978-3-031-49002-6_17</a>
|
114 |
+
</div>
|
115 |
+
""")
|
116 |
+
|
117 |
+
demo.launch()
|