Spaces:
Sleeping
Sleeping
Added my Project App and Files
Browse files- app.py +114 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import transformers
|
| 3 |
+
import torch
|
| 4 |
+
import requests
|
| 5 |
+
from PIL import Image
|
| 6 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 7 |
+
|
| 8 |
+
# Setting the page configurations
|
| 9 |
+
st.set_page_config(
|
| 10 |
+
page_title="Fake News Detection App",
|
| 11 |
+
page_icon="fas fa-exclamation-triangle",
|
| 12 |
+
layout="wide",
|
| 13 |
+
initial_sidebar_state="auto")
|
| 14 |
+
|
| 15 |
+
# Load the model and tokenizer
|
| 16 |
+
model_name = AutoModelForSequenceClassification.from_pretrained("ikoghoemmanuell/finetuned_fake_news_roberta")
|
| 17 |
+
tokenizer_name = AutoTokenizer.from_pretrained("ikoghoemmanuell/finetuned_fake_news_roberta")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Define the CSS style for the app
|
| 21 |
+
st.markdown(
|
| 22 |
+
"""
|
| 23 |
+
<style>
|
| 24 |
+
body {
|
| 25 |
+
background-color: #f5f5f5;
|
| 26 |
+
}
|
| 27 |
+
h1 {
|
| 28 |
+
color: #4e79a7;
|
| 29 |
+
}
|
| 30 |
+
</style>
|
| 31 |
+
""",
|
| 32 |
+
unsafe_allow_html=True
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Set up sidebar
|
| 36 |
+
st.sidebar.header('Navigation')
|
| 37 |
+
menu = ['Home', 'About']
|
| 38 |
+
choice = st.sidebar.selectbox(
|
| 39 |
+
"Select an option",
|
| 40 |
+
menu)
|
| 41 |
+
|
| 42 |
+
# Define the function for detecting fake news
|
| 43 |
+
@st.cache_resource
|
| 44 |
+
def detect_fake_news(text):
|
| 45 |
+
# Load the pipeline.
|
| 46 |
+
pipeline = transformers.pipeline("text-classification",
|
| 47 |
+
model=model_name,
|
| 48 |
+
tokenizer=tokenizer_name)
|
| 49 |
+
|
| 50 |
+
# Predict the sentiment.
|
| 51 |
+
prediction = pipeline(text)
|
| 52 |
+
sentiment = prediction[0]["label"]
|
| 53 |
+
score = prediction[0]["score"]
|
| 54 |
+
|
| 55 |
+
return sentiment, score
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
# Home section
|
| 59 |
+
if choice == 'Home':
|
| 60 |
+
st.markdown("<h1 style='text-align: center;margin-top:0px;'>TRUTH- A fake news detection app</h1>",
|
| 61 |
+
unsafe_allow_html=True)
|
| 62 |
+
|
| 63 |
+
# Loading GIF
|
| 64 |
+
gif_url = "https://thumbs.gfycat.com/AnchoredWeeklyGreatwhiteshark-size_restricted.gif"
|
| 65 |
+
st.image(gif_url,
|
| 66 |
+
use_column_width=True,
|
| 67 |
+
width=400)
|
| 68 |
+
|
| 69 |
+
st.markdown("<h1 style='text-align: center;'>Welcome</h1>",
|
| 70 |
+
unsafe_allow_html=True)
|
| 71 |
+
st.markdown("<p style='text-align: center;'>This is a Fake News Detection App.</p>",
|
| 72 |
+
unsafe_allow_html=True)
|
| 73 |
+
|
| 74 |
+
# Get user input
|
| 75 |
+
text = st.text_input("Enter some text and we'll tell you if it's likely to be fake news or not!")
|
| 76 |
+
|
| 77 |
+
if st.button('Predict'):
|
| 78 |
+
# Show fake news detection output
|
| 79 |
+
if text:
|
| 80 |
+
with st.spinner('Checking if news is Fake...'):
|
| 81 |
+
label, score = detect_fake_news(text)
|
| 82 |
+
if label == "LABEL_1":
|
| 83 |
+
st.error(f"The text is likely to be fake news with a confidence score of {score*100:.2f}%!")
|
| 84 |
+
else:
|
| 85 |
+
st.success(f"The text is likely to be genuine with a confidence score of {score*100:.2f}%!")
|
| 86 |
+
else:
|
| 87 |
+
with st.spinner('Checking if news is Fake...'):
|
| 88 |
+
st.warning("Please enter some text to detect fake news.")
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# About section
|
| 92 |
+
if choice == 'About':
|
| 93 |
+
# Load the banner image
|
| 94 |
+
banner_image_url = "https://docs.gato.txst.edu/78660/w/2000/a_1dzGZrL3bG/fake-fact.jpg"
|
| 95 |
+
|
| 96 |
+
# Display the banner image
|
| 97 |
+
st.image(
|
| 98 |
+
banner_image_url,
|
| 99 |
+
use_column_width=True,
|
| 100 |
+
width=400)
|
| 101 |
+
st.markdown('''
|
| 102 |
+
<p style='font-size: 20px; font-style: italic;font-style: bold;'>
|
| 103 |
+
|
| 104 |
+
TRUTH is a cutting-edge application specifically designed to combat the spread of fake
|
| 105 |
+
news. Using state-of-the-art algorithms and advanced deep learning techniques, our app
|
| 106 |
+
empowers users to detect and verify the authenticity of news articles. TRUTH provides
|
| 107 |
+
accurate assessments of the reliability of news content. With its user-friendly
|
| 108 |
+
interface and intuitive design, the app enables users to easily navigate and obtain
|
| 109 |
+
trustworthy information in real-time. With TRUTH, you can take control of the news you
|
| 110 |
+
consume and make informed decisions based on verified facts.
|
| 111 |
+
|
| 112 |
+
</p>
|
| 113 |
+
''',
|
| 114 |
+
unsafe_allow_html=True)
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
transformers
|