-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbase_app.py
80 lines (61 loc) · 2.64 KB
/
base_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Simple Streamlit webserver application for serving developed classification
models.
Author: ExploreAI Academy.
Note:
---------------------------------------------------------------------
Please follow the instructions provided within the README.md file
located within this directory for guidance on how to use this script
correctly.
---------------------------------------------------------------------
Description: This file is used to launch a minimal streamlit web
application. You are expected to extend the functionality of this script
as part of your predict project.
For further help with the Streamlit framework, see:
https://docs.streamlit.io/en/latest/
"""
# Streamlit dependencies
import streamlit as st
import joblib,os
# Data dependencies
import pandas as pd
# Vectorizer
#news_vectorizer = open("streamlit/tfidfvect.pkl","rb")
#test_cv = joblib.load(news_vectorizer) # loading your vectorizer from the pkl file
# Load your raw data
#raw = pd.read_csv("streamlit/train.csv")
# The main function where we will build the actual app
def main():
"""News Classifier App with Streamlit """
# Creates a main title and subheader on your page -
# these are static across all pages
st.title("News Classifer")
st.subheader("Analysing news articles")
# Creating sidebar with selection box -
# you can create multiple pages this way
options = ["Prediction", "Information"]
selection = st.sidebar.selectbox("Choose Option", options)
# Building out the "Information" page
if selection == "Information":
st.info("General Information")
# You can read a markdown file from supporting resources folder
st.markdown("Some information here")
# Building out the predication page
if selection == "Prediction":
st.info("Prediction with ML Models")
# Creating a text box for user input
news_text = st.text_area("Enter Text","Type Here")
if st.button("Classify"):
# Transforming user input with vectorizer
vect_text = test_cv.transform([news_text]).toarray()
# Load your .pkl file with the model of your choice + make predictions
# Try loading in multiple models to give the user a choice
predictor = joblib.load(open(os.path.join("streamlit/Logistic_regression.pkl"),"rb"))
prediction = predictor.predict(vect_text)
# When model has successfully run, will print prediction
# You can use a dictionary or similar structure to make this output
# more human interpretable.
st.success("Text Categorized as: {}".format(prediction))
# Required to let Streamlit instantiate our web app.
if __name__ == '__main__':
main()