Nimzi commited on
Commit
d006eb0
Β·
verified Β·
1 Parent(s): 873f8c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -53
app.py CHANGED
@@ -14,9 +14,6 @@ fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-fi
14
  st.set_page_config(page_title="Fake News Detector", layout="wide")
15
  st.title("πŸ“° Fake News Detector")
16
 
17
- # Tabs for Input and Results
18
- tab1, tab2 = st.tabs(["Input", "Results"])
19
-
20
  # Function to fetch real news links from various open sources
21
  def fetch_real_news_links():
22
  return [
@@ -29,59 +26,58 @@ def fetch_real_news_links():
29
  "https://www.factcheck.org"
30
  ]
31
 
32
- with tab1:
33
- st.sidebar.title("Select Input Type")
34
- option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
 
 
 
 
 
 
 
 
35
 
36
- if option == "Text":
37
- news_text = st.text_area("Enter the news content to check:", height=200)
38
- if st.button("Analyze News"):
39
- if not news_text.strip():
40
- st.warning("Please enter some text.")
41
- else:
42
- st.session_state["news_text"] = news_text
43
- st.session_state["analyze"] = True
44
- st.rerun()
45
 
46
- elif option == "Image":
47
- uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
48
- if uploaded_file is not None:
49
- st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
50
- st.info("πŸ” Image analysis coming soon!")
51
 
52
- elif option == "Video Link":
53
- video_url = st.text_input("Enter a video news link to check")
54
- if st.button("Analyze Video"):
55
- if not video_url.strip():
56
- st.warning("Please enter a valid URL.")
57
- else:
58
- st.info("πŸ” Video analysis coming soon!")
 
59
 
60
- with tab2:
61
- if st.session_state.get("analyze", False):
62
  news_text = st.session_state.get("news_text", "")
63
- with st.spinner("Analyzing..."):
64
- # Check using Hugging Face model
 
65
  hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
66
-
67
- # Display result
68
- if hf_result == "fake":
69
- st.error("❌ This news is likely **Fake**!", icon="⚠️")
70
- st.markdown('<style>div.stAlert {background-color: #ffdddd;}</style>', unsafe_allow_html=True)
71
- conclusion = "The analysis suggests that this news might be fabricated or misleading. Please verify from credible sources."
72
- elif hf_result == "real":
73
- st.success("βœ… This news is likely **Real**!", icon="βœ…")
74
- st.markdown('<style>div.stAlert {background-color: #ddffdd;}</style>', unsafe_allow_html=True)
75
- conclusion = "The analysis indicates that this news appears to be credible and factual."
76
- else:
77
- st.info("πŸ€” The result is uncertain. Please verify from trusted sources.")
78
- conclusion = "There is uncertainty in the classification. Further verification is recommended."
79
-
80
- # Conclusion Section
81
- st.subheader("πŸ“Œ Conclusion")
82
- st.write(conclusion)
83
-
84
- # Display real news sources
85
- st.subheader("πŸ”— Reliable News Sources")
86
- for link in fetch_real_news_links():
87
- st.markdown(f"[πŸ”— {link}]({link})")
 
14
  st.set_page_config(page_title="Fake News Detector", layout="wide")
15
  st.title("πŸ“° Fake News Detector")
16
 
 
 
 
17
  # Function to fetch real news links from various open sources
18
  def fetch_real_news_links():
19
  return [
 
26
  "https://www.factcheck.org"
27
  ]
28
 
29
+ # Input Section
30
+ st.sidebar.title("Select Input Type")
31
+ option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
32
+
33
+ if option == "Text":
34
+ news_text = st.text_area("Enter the news content to check:", height=200)
35
+ analyze_text = st.button("Analyze Text")
36
+
37
+ elif option == "Image":
38
+ uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
39
+ analyze_image = st.button("Analyze Image")
40
 
41
+ elif option == "Video Link":
42
+ video_url = st.text_input("Enter a video news link to check")
43
+ analyze_video = st.button("Analyze Video")
 
 
 
 
 
 
44
 
45
+ # Results Section
46
+ if "analyze" not in st.session_state:
47
+ st.session_state["analyze"] = False
 
 
48
 
49
+ if (option == "Text" and analyze_text and news_text.strip()) or \
50
+ (option == "Image" and analyze_image and uploaded_file) or \
51
+ (option == "Video Link" and analyze_video and video_url.strip()):
52
+ st.session_state["analyze"] = True
53
+ st.session_state["news_text"] = news_text if option == "Text" else ""
54
+ st.session_state["uploaded_file"] = uploaded_file if option == "Image" else None
55
+ st.session_state["video_url"] = video_url if option == "Video Link" else ""
56
+ st.rerun()
57
 
58
+ if st.session_state["analyze"]:
59
+ with st.spinner("Analyzing..."):
60
  news_text = st.session_state.get("news_text", "")
61
+ hf_result = "uncertain"
62
+
63
+ if news_text:
64
  hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
65
+
66
+ if hf_result == "fake":
67
+ st.error("❌ This news is likely **Fake**!", icon="⚠️")
68
+ conclusion = "The analysis suggests that this news might be fabricated or misleading. Please verify from credible sources."
69
+ elif hf_result == "real":
70
+ st.success("βœ… This news is likely **Real**!", icon="βœ…")
71
+ conclusion = "The analysis indicates that this news appears to be credible and factual."
72
+ else:
73
+ st.info("πŸ€” The result is uncertain. Please verify from trusted sources.")
74
+ conclusion = "There is uncertainty in the classification. Further verification is recommended."
75
+
76
+ # Conclusion Section
77
+ st.subheader("πŸ“Œ Conclusion")
78
+ st.write(conclusion)
79
+
80
+ # Display real news sources
81
+ st.subheader("πŸ”— Reliable News Sources")
82
+ for link in fetch_real_news_links():
83
+ st.markdown(f"[πŸ”— {link}]({link})")