-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.py
56 lines (45 loc) · 1.7 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
48
49
50
51
52
53
54
55
56
import streamlit as st
import altair as alt
import pandas as pd
import numpy as np
import joblib
# Load pipeline
pipeline = joblib.load("fake_news_classifier_pipeline.pkl")
def predict_fakenews(docx):
results = pipeline.predict([docx])
return results[0]
def get_prediction_proba(docx):
results = pipeline.predict_proba([docx])
return results
news_emoji_dict = {"Fake": "🚫", "Real": "✅"}
def main():
st.title("Bangla Fake News Classifier")
st.subheader("Input Text")
with st.form(key='fakenews_clf_form'):
raw_text = st.text_area("Type Here")
submit_text = st.form_submit_button(label='Submit')
if submit_text:
col1, col2 = st.columns(2)
# Apply functions
prediction = predict_fakenews(raw_text)
probability = get_prediction_proba(raw_text)
with col1:
st.success("Original Text")
st.write(raw_text)
st.success("Prediction")
news_icon = news_emoji_dict[prediction]
st.write(f"{prediction}: {news_icon}")
st.write(f"Confidence: {np.max(probability)}")
with col2:
st.success("Prediction Probability")
proba_df = pd.DataFrame(probability, columns=pipeline.classes_)
proba_df_clean = proba_df.T.reset_index()
proba_df_clean.columns = ["news type", "probability"]
fig = alt.Chart(proba_df_clean).mark_bar().encode(
x='news type',
y='probability',
color='news type'
)
st.altair_chart(fig, use_container_width=True)
if __name__ == '__main__':
main()