Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle
|
3 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
4 |
+
from sklearn.linear_model import PassiveAggressiveClassifier
|
5 |
+
model = PassiveAggressiveClassifier(max_iter=50)
|
6 |
+
|
7 |
+
with open('tfidf.pickle', 'rb') as f:
|
8 |
+
tfidf = pickle.load(f)
|
9 |
+
|
10 |
+
PAGE_CONFIG = {"page_title":"My first ML app","page_icon":":smiley:","layout":"centered"}
|
11 |
+
st.set_page_config(**PAGE_CONFIG)
|
12 |
+
st.title("My first ML app")
|
13 |
+
st.subheader("Here is my awesome learning result")
|
14 |
+
|
15 |
+
menu = ["Home","About my startup"]
|
16 |
+
choice = st.sidebar.selectbox('Menu',menu)
|
17 |
+
if choice == 'Home':
|
18 |
+
st.subheader("Let's get down to the details.")
|
19 |
+
|
20 |
+
title = st.text_input('News title', 'Queen Elizabeth buys an Unicorn')
|
21 |
+
|
22 |
+
with open('model.pkl', 'rb') as f:
|
23 |
+
model = pickle.load(f)
|
24 |
+
|
25 |
+
def predict_news(news_text):
|
26 |
+
prediction = model.predict(tfidf.transform([news_text]))
|
27 |
+
if prediction[0] == 1:
|
28 |
+
return("Possibly fake news")
|
29 |
+
else:
|
30 |
+
return("Possibly real news")
|
31 |
+
|
32 |
+
result = predict_news(title)
|
33 |
+
st.write('Fake classification: ', result)
|