-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
47 lines (35 loc) · 1.28 KB
/
app.py
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
41
42
43
44
45
46
47
import streamlit as st
import requests as r
from langdetect import detect
# add banner image
st.header("Swahili News classifier App")
st.image("images/swahili-news.png")
st.subheader(
"""
A simple app to classify swahili news into different categories.
"""
)
# form to collect news content
my_form = st.form(key="news_form")
news = my_form.text_input("Input your swahili news content here")
submit = my_form.form_submit_button(label="Classify news content")
if submit:
# classify news content by using the API URL provided
if detect(news) == "sw":
keys = {"news": news}
prediction = r.get(
"https://limitless-forest-00896.herokuapp.com/news-prediction/", params=keys
)
# collect and print the result
results = prediction.json()
category = results["prediction"]
probability = results["Probability"]
# Display results of the NLP task
st.header("Results")
st.write(
"News category is {} with a probabiliy of {} ".format(category, probability)
)
else:
st.write(" ⚠️ The news content is not in swahili language.Please make sure the input is in swahili language")
url = "https://twitter.com/Davis_McDavid"
st.write("Developed with ❤️ by [Davis David](%s)" % url)