Nimzi commited on
Commit
7febe8b
Β·
verified Β·
1 Parent(s): deb37d9

Update app.py

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