import pandas as pd import numpy as np from sklearn.feature_extraction.text import CountVectorizer from sklearn.model_selection import train_test_split from sklearn.naive_bayes import MultinomialNB import streamlit as st # Set page title and icon st.set_page_config(page_title='Fake News Detection', page_icon=":postal_horn:") # Load the dataset df = pd.read_csv("fake_or_real_news.csv") # Train the model x = np.array(df["title"]) y = np.array(df["label"]) cv = CountVectorizer() x = cv.fit_transform(x) xtrain, xtest, ytrain, ytest = train_test_split(x, y, test_size=0.2, random_state=42) model = MultinomialNB() model.fit(xtrain, ytrain) st.title('Fake News Detection :postal_horn:') # Display an image st.image("https://upload.wikimedia.org/wikipedia/commons/f/f7/The_fin_de_siècle_newspaper_proprietor_%28cropped%29.jpg") # Input field for user to enter news headline default_example = "Aliens decided to buy America after Russia Exploded" news_headline = st.text_input("Enter a news headline:", default_example) if st.button("Check"): # Make prediction df_input = cv.transform([news_headline]).toarray() prediction = model.predict(df_input) # Display prediction result if prediction[0] == 'FAKE': st.error("This news headline is likely FAKE.") else: st.success("This news headline is likely REAL.")