ikoghoemmanuell commited on
Commit
a1d0b3c
1 Parent(s): b395baf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -30
app.py CHANGED
@@ -8,38 +8,82 @@ from predict_function import detect_fake_news
8
  model_name = AutoModelForSequenceClassification.from_pretrained("ikoghoemmanuell/finetuned_fake_news_roberta")
9
  tokenizer_name = AutoTokenizer.from_pretrained("ikoghoemmanuell/finetuned_fake_news_roberta")
10
 
11
- # # Set Page Configurations
12
- # st.set_page_config(page_title="Fake News Detection App", page_icon="fas fa-exclamation-triangle", layout="wide", initial_sidebar_state="auto")
13
 
14
- # # Loading GIF
15
- # gif_url = "https://raw.githubusercontent.com/Gilbert-B/Forecasting-Sales/main/app/salesgif.gif"
 
16
 
17
- # # Set up sidebar
18
- # st.sidebar.header('Navigation')
19
- # menu = ['Home', 'About']
20
- # choice = st.sidebar.selectbox("Select an option", menu)
21
 
 
 
 
 
 
22
 
23
- # Setting the page configurations
24
- st.set_page_config(
25
- page_title="Fake News Detection App",
26
- page_icon=":smile:",
27
- layout="wide",
28
- initial_sidebar_state="auto",
29
- )
30
 
31
- # Add description and title
32
- st.write("""
33
- # Fake News Detection
34
- Enter some text and we'll tell you if it's likely to be fake news or not!
35
- """)
36
 
37
- # Add image
38
- image = st.image("https://docs.gato.txst.edu/78660/w/2000/a_1dzGZrL3bG/fake-fact.jpg", width=400)
39
 
40
  # Get user input
41
  text = st.text_input("Enter some text here:")
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  # Define the CSS style for the app
44
  st.markdown(
45
  """
@@ -55,11 +99,22 @@ h1 {
55
  unsafe_allow_html=True
56
  )
57
 
58
- # Show fake news detection output
59
- if text:
60
- label, score = detect_fake_news(text)
61
- print(label, score)
62
- if label == "LABEL_1":
63
- st.error(f"The text is likely to be fake news with a confidence score of {score*100:.2f}%!")
64
- else:
65
- st.success(f"The text is likely to be genuine with a confidence score of {score*100:.2f}%!")
 
 
 
 
 
 
 
 
 
 
 
 
8
  model_name = AutoModelForSequenceClassification.from_pretrained("ikoghoemmanuell/finetuned_fake_news_roberta")
9
  tokenizer_name = AutoTokenizer.from_pretrained("ikoghoemmanuell/finetuned_fake_news_roberta")
10
 
 
 
11
 
12
+ # Loading GIF
13
+ gif_url = "https://raw.githubusercontent.com/Gilbert-B/Forecasting-Sales/main/app/salesgif.gif"
14
+ "https://docs.gato.txst.edu/78660/w/2000/a_1dzGZrL3bG/fake-fact.jpg"
15
 
16
+ # Set up sidebar
17
+ st.sidebar.header('Navigation')
18
+ menu = ['Home', 'About']
19
+ choice = st.sidebar.selectbox("Select an option", menu)
20
 
21
+ # Define the function for detecting fake news
22
+ @st.cache_resource
23
+ def detect_fake_news(text):
24
+ # Load the pipeline.
25
+ pipeline = transformers.pipeline("text-classification", model=model_name, tokenizer=tokenizer_name)
26
 
27
+ # Predict the sentiment.
28
+ prediction = pipeline(text)
29
+ sentiment = prediction[0]["label"]
30
+ score = prediction[0]["score"]
 
 
 
31
 
32
+ return sentiment, score
 
 
 
 
33
 
 
 
34
 
35
  # Get user input
36
  text = st.text_input("Enter some text here:")
37
 
38
+
39
+
40
+ # Home section
41
+ if choice == 'Home':
42
+ st.image(gif_url,
43
+ use_column_width=True,
44
+ width=400)
45
+ st.markdown("<h1 style='text-align: center;'>Welcome</h1>", unsafe_allow_html=True)
46
+ st.markdown("<p style='text-align: center;'>This is a Fake News Detection App.</p>", unsafe_allow_html=True)
47
+
48
+ # Set Page Title
49
+ st.title('TRUTH- A fake news detection app')
50
+ st.markdown('Enter some text and we'll tell you if it's likely to be fake news or not!')
51
+
52
+
53
+
54
+ if st.button('Predict'):
55
+ # Show fake news detection output
56
+ if text:
57
+ with st.spinner('Checking if news is Fake...'):
58
+ label, score = detect_fake_news(text)
59
+ print(label, score)
60
+ if label == "LABEL_1":
61
+ st.error(f"The text is likely to be fake news with a confidence score of {score*100:.2f}%!")
62
+ else:
63
+ st.success(f"The text is likely to be genuine with a confidence score of {score*100:.2f}%!")
64
+ else:
65
+ with st.spinner('Checking if news is Fake...'):
66
+ sales_data = pd.DataFrame({})
67
+ try:
68
+ st.success(f"")
69
+ except ValueError as e:
70
+ st.error(str(e))
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+ # Setting the page configurations
85
+ st.set_page_config(page_title="Fake News Detection App", page_icon="fas fa-exclamation-triangle", layout="wide", initial_sidebar_state="auto")
86
+
87
  # Define the CSS style for the app
88
  st.markdown(
89
  """
 
99
  unsafe_allow_html=True
100
  )
101
 
102
+ # About section
103
+ elif choice == 'About':
104
+ # Load the banner image
105
+ banner_image_url = "https://raw.githubusercontent.com/Gilbert-B/Forecasting-Sales/0d7b869515bniVmJZZxhyQ8Fee6m6SCLi64M8Ba72c/app/seer.png"
106
+ banner_image = Image.open(requests.get(banner_image_url, stream=True).raw)
107
+
108
+ # Display the banner image
109
+ st.image(banner_image, use_column_width=True)
110
+ st.markdown('''
111
+ <p style='font-size: 20px; font-style: italic;font-style: bold;'>
112
+ TRUTH is a cutting-edge application specifically designed to combat the spread of fake news.
113
+ Using state-of-the-art algorithms and advanced deep learning techniques,
114
+ our app empowers users to detect and verify the authenticity of news articles.
115
+ TRUTH provides accurate assessments of the reliability of news content.
116
+ With its user-friendly interface and intuitive design,
117
+ the app enables users to easily navigate and obtain trustworthy information in real-time.
118
+ With TRUTH, you can take control of the news you consume and make informed decisions based on verified facts.
119
+ </p>
120
+ ''', unsafe_allow_html=True)