ikoghoemmanuell commited on
Commit
b291470
1 Parent(s): 1dfa57b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +64 -0
  2. requirements.txt +11 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import transformers
3
+ import torch
4
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
5
+
6
+ # Load the model and tokenizer
7
+ model = AutoModelForSequenceClassification.from_pretrained("ikoghoemmanuell/finetuned_fake_news_bert")
8
+ tokenizer = AutoTokenizer.from_pretrained("ikoghoemmanuell/finetuned_fake_news_bert")
9
+
10
+ # Define the function for detecting fake news
11
+ @st.cache_resource
12
+ def detect_fake_news(text):
13
+ # Load the pipeline.
14
+ pipeline = transformers.pipeline("text-classification")
15
+
16
+ # Predict the sentiment.
17
+ prediction = pipeline(text)
18
+ sentiment = prediction[0]["label"]
19
+ score = prediction[0]["score"]
20
+
21
+ return sentiment, score
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
+ """
46
+ <style>
47
+ body {
48
+ background-color: #f5f5f5;
49
+ }
50
+ h1 {
51
+ color: #4e79a7;
52
+ }
53
+ </style>
54
+ """,
55
+ unsafe_allow_html=True
56
+ )
57
+
58
+ # Show fake news detection output
59
+ if text:
60
+ label, score = detect_fake_news(text)
61
+ if label == "Fake":
62
+ st.error(f"The text is likely to be fake news with a confidence score of {score*100:.2f}%!")
63
+ else:
64
+ st.success(f"The text is likely to be genuine with a confidence score of {score*100:.2f}%!")
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ # pandas==1.5.3
3
+ # numpy==1.24.2
4
+ # pillow
5
+ # requests
6
+ # bokeh
7
+ # scikit-learn==1.2.2
8
+
9
+ # for huggingface app
10
+ torch
11
+ transformers