File size: 2,268 Bytes
cdc5f3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc5f98f
 
cdc5f3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import transformers
import torch
import requests
from PIL import Image
from transformers import AutoTokenizer, AutoModelForSequenceClassification

# Setting the page configurations
st.set_page_config(
    page_title="Fake News Detection App", 
    page_icon="fas fa-exclamation-triangle", 
    layout="wide", 
    initial_sidebar_state="auto")

# Load the model and tokenizer
tokenizer_name = AutoTokenizer.from_pretrained("jy46604790/Fake-News-Bert-Detect")
model_name = AutoModelForSequenceClassification.from_pretrained("jy46604790/Fake-News-Bert-Detect")


# Define the CSS style for the app
st.markdown(
"""
<style>
body {
    background-color: #f5f5f5;
}
h1 {
    color: #4e79a7;
}
</style>
""",
unsafe_allow_html=True
)

# Define the function for detecting fake news
@st.cache_resource
def detect_fake_news(text):
    # Load the pipeline.
    pipeline = transformers.pipeline("text-classification", 
                                     model=model_name, 
                                     tokenizer=tokenizer_name)

    # Predict the sentiment.
    prediction = pipeline(text)
    sentiment = prediction[0]["label"]
    score = prediction[0]["score"]

    return sentiment, score


st.markdown("<h1 style='text-align: center;margin-top:0px;'>A fake news detection app</h1>", 
            unsafe_allow_html=True)

st.markdown("<h1 style='text-align: center;'>Welcome</h1>", 
            unsafe_allow_html=True)
st.markdown("<p style='text-align: center;'>This is a Fake News Detection App.</p>", 
            unsafe_allow_html=True)

# Get user input
text = st.text_input("Enter some text and we'll tell you if it's likely to be fake news or not!")

if st.button('Predict'):
    # Show fake news detection output
    if text:
        with st.spinner('Checking if news is Fake...'):
            label, score = detect_fake_news(text)
            if label == "FAKE":
                st.error(f"The text is likely to be fake news with a confidence score of {score*100:.2f}%!")
            else:
                st.success(f"The text is likely to be genuine with a confidence score of {score*100:.2f}%!")
    else:
        with st.spinner('Checking if news is Fake...'):
            st.warning("Please enter some text to detect fake news.")