zionia commited on
Commit
7fee8c9
1 Parent(s): 6b23fac

update css integration

Browse files
Files changed (1) hide show
  1. app.py +35 -32
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,10 +30,10 @@ 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
 
38
  results = []
39
  for news in news_list:
@@ -41,24 +41,6 @@ def file_prediction(file):
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
- )
51
-
52
- gradio_file_ui = gr.Interface(
53
- fn=file_prediction,
54
- title="Upload File for Setswana News Classification",
55
- description=f"Upload a text or CSV file with Setswana news articles. The first column in the CSV should contain the news text.",
56
- inputs=gr.File(label="Upload text or CSV file"),
57
- outputs=gr.Dataframe(headers=["News Text", "Category Predictions"], label="Predictions from file"),
58
- )
59
-
60
- gradio_combined_ui = gr.TabbedInterface([gradio_ui, gradio_file_ui], ["Text Input", "File Upload"])
61
-
62
  css = """
63
  body {
64
  background-color: white !important;
@@ -88,4 +70,25 @@ body {
88
  }
89
  """
90
 
91
- gradio_combined_ui.launch(css=css)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  model = AutoModelForSequenceClassification.from_pretrained("dsfsi/PuoBERTa-News")
10
 
11
  categories = {
12
+ "arts_culture_entertainment_and_media": "Botsweretshi, setso, boitapoloso le bobegakgang/Arts, culture, entertainment and media",
13
+ "crime_law_and_justice": "Bosenyi, molao le bosiamisi/Crime, law and justice",
14
+ "disaster_accident_and_emergency_incident": "Masetlapelo, kotsi le tiragalo ya maemo a tshoganyetso/Disaster, accident and emergency incident",
15
+ "economy_business_and_finance": "Ikonomi, tsa kgwebo le tsa ditšhelete/Economy, business and finance",
16
+ "education": "Thuto/Education",
17
+ "environment": "Tikologo/Environment",
18
+ "health": "Boitekanelo/Health",
19
+ "politics": "Dipolotiki/Politics",
20
+ "religion_and_belief": "Bodumedi le tumelo/Religion and belief",
21
+ "society": "Setšhaba/Society"
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
 
38
  results = []
39
  for news in news_list:
 
41
 
42
  return results
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  css = """
45
  body {
46
  background-color: white !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
+ css=css
80
+ )
81
+
82
+ gradio_file_ui = gr.Interface(
83
+ fn=file_prediction,
84
+ title="Upload File for Setswana News Classification",
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
+ css=css
89
+ )
90
+
91
+ gradio_combined_ui = gr.TabbedInterface([gradio_ui, gradio_file_ui], ["Text Input", "File Upload"])
92
+
93
+ gradio_combined_ui.launch()
94
+