use huggingface theme
Browse files
app.py
CHANGED
@@ -9,16 +9,16 @@ tokenizer = AutoTokenizer.from_pretrained("dsfsi/PuoBERTa-News")
|
|
9 |
model = AutoModelForSequenceClassification.from_pretrained("dsfsi/PuoBERTa-News")
|
10 |
|
11 |
categories = {
|
12 |
-
"arts_culture_entertainment_and_media": "Botsweretshi, setso, boitapoloso le bobegakgang
|
13 |
-
"crime_law_and_justice": "Bosenyi, molao le bosiamisi
|
14 |
-
"disaster_accident_and_emergency_incident": "Masetlapelo, kotsi le tiragalo ya maemo a tshoganyetso
|
15 |
-
"economy_business_and_finance": "Ikonomi, tsa kgwebo le tsa ditšhelete
|
16 |
-
"education": "Thuto
|
17 |
-
"environment": "Tikologo
|
18 |
-
"health": "Boitekanelo
|
19 |
-
"politics": "Dipolotiki
|
20 |
-
"religion_and_belief": "Bodumedi le tumelo
|
21 |
-
"society": "Setšhaba
|
22 |
}
|
23 |
|
24 |
def prediction(news):
|
@@ -30,8 +30,8 @@ def prediction(news):
|
|
30 |
def file_prediction(file):
|
31 |
# Load the file (CSV or text)
|
32 |
if file.name.endswith('.csv'):
|
33 |
-
df = pd.read_csv(file.name)
|
34 |
-
news_list = df.iloc[:, 0].tolist()
|
35 |
else:
|
36 |
news_list = [file.read().decode('utf-8')]
|
37 |
|
@@ -41,42 +41,14 @@ def file_prediction(file):
|
|
41 |
|
42 |
return results
|
43 |
|
44 |
-
css = """
|
45 |
-
body {
|
46 |
-
background-color: white !important;
|
47 |
-
color: black !important;
|
48 |
-
}
|
49 |
-
|
50 |
-
.gradio-container {
|
51 |
-
background-color: white !important;
|
52 |
-
color: black !important;
|
53 |
-
}
|
54 |
-
|
55 |
-
.gr-input, .gr-button, .gr-textbox, .gr-file, .gr-dataframe {
|
56 |
-
background-color: white !important;
|
57 |
-
color: black !important;
|
58 |
-
border-color: #ccc !important;
|
59 |
-
}
|
60 |
-
|
61 |
-
.gr-button {
|
62 |
-
background-color: #f0f0f0 !important;
|
63 |
-
color: black !important;
|
64 |
-
border: 1px solid #ccc !important;
|
65 |
-
}
|
66 |
-
|
67 |
-
.gr-dataframe th, .gr-dataframe td {
|
68 |
-
background-color: #f9f9f9 !important;
|
69 |
-
color: black !important;
|
70 |
-
}
|
71 |
-
"""
|
72 |
-
|
73 |
gradio_ui = gr.Interface(
|
74 |
fn=prediction,
|
75 |
title="Setswana News Classification",
|
76 |
description=f"Enter Setswana news article to see the category of the news.\n For this classification, the {MODEL_URL} model was used.",
|
77 |
inputs=gr.Textbox(lines=10, label="Paste some Setswana news here"),
|
78 |
outputs=gr.Label(num_top_classes=5, label="News categories probabilities"),
|
79 |
-
|
|
|
80 |
)
|
81 |
|
82 |
gradio_file_ui = gr.Interface(
|
@@ -85,10 +57,9 @@ gradio_file_ui = gr.Interface(
|
|
85 |
description=f"Upload a text or CSV file with Setswana news articles. The first column in the CSV should contain the news text.",
|
86 |
inputs=gr.File(label="Upload text or CSV file"),
|
87 |
outputs=gr.Dataframe(headers=["News Text", "Category Predictions"], label="Predictions from file"),
|
88 |
-
|
89 |
)
|
90 |
|
91 |
gradio_combined_ui = gr.TabbedInterface([gradio_ui, gradio_file_ui], ["Text Input", "File Upload"])
|
92 |
|
93 |
gradio_combined_ui.launch()
|
94 |
-
|
|
|
9 |
model = AutoModelForSequenceClassification.from_pretrained("dsfsi/PuoBERTa-News")
|
10 |
|
11 |
categories = {
|
12 |
+
"arts_culture_entertainment_and_media": "Botsweretshi, setso, boitapoloso le bobegakgang",
|
13 |
+
"crime_law_and_justice": "Bosenyi, molao le bosiamisi",
|
14 |
+
"disaster_accident_and_emergency_incident": "Masetlapelo, kotsi le tiragalo ya maemo a tshoganyetso",
|
15 |
+
"economy_business_and_finance": "Ikonomi, tsa kgwebo le tsa ditšhelete",
|
16 |
+
"education": "Thuto",
|
17 |
+
"environment": "Tikologo",
|
18 |
+
"health": "Boitekanelo",
|
19 |
+
"politics": "Dipolotiki",
|
20 |
+
"religion_and_belief": "Bodumedi le tumelo",
|
21 |
+
"society": "Setšhaba"
|
22 |
}
|
23 |
|
24 |
def prediction(news):
|
|
|
30 |
def file_prediction(file):
|
31 |
# Load the file (CSV or text)
|
32 |
if file.name.endswith('.csv'):
|
33 |
+
df = pd.read_csv(file.name)
|
34 |
+
news_list = df.iloc[:, 0].tolist()
|
35 |
else:
|
36 |
news_list = [file.read().decode('utf-8')]
|
37 |
|
|
|
41 |
|
42 |
return results
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
gradio_ui = gr.Interface(
|
45 |
fn=prediction,
|
46 |
title="Setswana News Classification",
|
47 |
description=f"Enter Setswana news article to see the category of the news.\n For this classification, the {MODEL_URL} model was used.",
|
48 |
inputs=gr.Textbox(lines=10, label="Paste some Setswana news here"),
|
49 |
outputs=gr.Label(num_top_classes=5, label="News categories probabilities"),
|
50 |
+
theme="huggingface", # Apply the dark mode theme
|
51 |
+
article="<p style='text-align: center'>For our other AI works: <a href='https://www.kodiks.com/ai_solutions.html' target='_blank'>https://www.kodiks.com/ai_solutions.html</a> | <a href='https://twitter.com/KodiksBilisim' target='_blank'>Contact us</a></p>",
|
52 |
)
|
53 |
|
54 |
gradio_file_ui = gr.Interface(
|
|
|
57 |
description=f"Upload a text or CSV file with Setswana news articles. The first column in the CSV should contain the news text.",
|
58 |
inputs=gr.File(label="Upload text or CSV file"),
|
59 |
outputs=gr.Dataframe(headers=["News Text", "Category Predictions"], label="Predictions from file"),
|
60 |
+
theme="huggingface" # Apply the dark mode theme
|
61 |
)
|
62 |
|
63 |
gradio_combined_ui = gr.TabbedInterface([gradio_ui, gradio_file_ui], ["Text Input", "File Upload"])
|
64 |
|
65 |
gradio_combined_ui.launch()
|
|