Nimzi commited on
Commit
a346939
Β·
verified Β·
1 Parent(s): c8d1c47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -49
app.py CHANGED
@@ -46,80 +46,76 @@ def check_video_fake_news(video_url):
46
  st.set_page_config(page_title="Fake News Detector", layout="wide")
47
  st.title("πŸ“° Fake News Detector")
48
 
49
- # πŸ”Ή Sidebar for Input Selection
50
- st.sidebar.title("Select Input Type")
51
- option = st.sidebar.radio("Choose an option", ["Text", "Image", "Video Link"])
52
 
53
- # πŸ”Ή Ensure session state variables are initialized
54
- for key in ["analyze_text", "result_text", "accuracy_text", "analyze_image", "analyze_video", "news_image", "video_url"]:
55
- if key not in st.session_state:
56
- st.session_state[key] = None
57
 
58
  # πŸ”Ή Text Input Section
59
- if option == "Text":
60
- news_text = st.text_area("Enter the news content to check:", height=200)
61
- if st.button("Analyze News"):
 
 
 
62
  if not news_text.strip():
63
  st.warning("Please enter some text.")
64
  else:
65
  result, accuracy = classify_text(news_text)
66
- st.session_state["result_text"] = result
67
- st.session_state["accuracy_text"] = accuracy
68
 
69
  # πŸ”Ή Image Upload Section
70
- elif option == "Image":
 
71
  uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
72
- if uploaded_image and st.button("Analyze Image"):
 
 
73
  image = Image.open(uploaded_image)
74
- st.session_state["news_image"] = image
75
  result, accuracy = analyze_image(image)
76
- st.session_state["result_text"] = result
77
- st.session_state["accuracy_text"] = accuracy
 
78
 
79
  # πŸ”Ή Video Link Section
80
- elif option == "Video Link":
 
81
  video_url = st.text_input("Enter the video link:")
82
- if st.button("Analyze Video"):
 
 
83
  if not video_url.strip():
84
  st.warning("Please enter a valid video link.")
85
  else:
86
- st.session_state["video_url"] = video_url
87
  result, accuracy = check_video_fake_news(video_url)
88
- st.session_state["result_text"] = result
89
- st.session_state["accuracy_text"] = accuracy
 
90
 
91
  # πŸ”Ή Results Section
92
  st.subheader("πŸ“Š Analysis Results")
93
- if st.session_state["result_text"]:
94
- result = st.session_state["result_text"]
95
- accuracy = st.session_state["accuracy_text"]
 
 
96
 
97
  if result == "Fake":
98
- st.error(f"❌ This is likely **Fake News**! (Accuracy: {accuracy}%)", icon="⚠️")
99
  else:
100
- st.success(f"βœ… This is likely **Real News**! (Accuracy: {accuracy}%)", icon="βœ…")
101
-
102
- # πŸ”Ή Verification Sources
103
- st.subheader("πŸ” Verification & Trusted Sources")
104
- sources = [
105
- "https://www.bbc.com/news",
106
- "https://www.cnn.com",
107
- "https://www.reuters.com",
108
- "https://factcheck.org",
109
- "https://www.snopes.com",
110
- "https://www.politifact.com"
111
- ]
112
- for link in sources:
113
- st.markdown(f"[πŸ”— {link}]({link})")
114
-
115
- if option == "Text":
116
- verification_link = verify_news(st.session_state["result_text"])
117
- st.markdown(f"[πŸ”Ž Verify on Google]({verification_link})")
118
-
119
- # πŸ”Ή Display Image if Uploaded
120
- if st.session_state["news_image"]:
121
  st.image(st.session_state["news_image"], caption="Uploaded Image", use_column_width=True)
 
122
 
123
- # πŸ”Ή Display Video if Entered
124
- if st.session_state["video_url"]:
125
  st.video(st.session_state["video_url"])
 
 
 
46
  st.set_page_config(page_title="Fake News Detector", layout="wide")
47
  st.title("πŸ“° Fake News Detector")
48
 
49
+ # πŸ”Ή Three Separate Sections for Input
50
+ st.subheader("πŸ” Choose an Input Type")
 
51
 
52
+ col1, col2, col3 = st.columns(3)
 
 
 
53
 
54
  # πŸ”Ή Text Input Section
55
+ with col1:
56
+ st.markdown("### πŸ“„ Text Input")
57
+ news_text = st.text_area("Enter the news content to check:", height=150)
58
+ analyze_text_clicked = st.button("Analyze News")
59
+
60
+ if analyze_text_clicked:
61
  if not news_text.strip():
62
  st.warning("Please enter some text.")
63
  else:
64
  result, accuracy = classify_text(news_text)
65
+ st.session_state["text_result"] = result
66
+ st.session_state["text_accuracy"] = accuracy
67
 
68
  # πŸ”Ή Image Upload Section
69
+ with col2:
70
+ st.markdown("### πŸ–ΌοΈ Image Upload")
71
  uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
72
+ analyze_image_clicked = st.button("Analyze Image")
73
+
74
+ if uploaded_image and analyze_image_clicked:
75
  image = Image.open(uploaded_image)
 
76
  result, accuracy = analyze_image(image)
77
+ st.session_state["image_result"] = result
78
+ st.session_state["image_accuracy"] = accuracy
79
+ st.session_state["news_image"] = image # Store Image for Display
80
 
81
  # πŸ”Ή Video Link Section
82
+ with col3:
83
+ st.markdown("### πŸŽ₯ Video Link")
84
  video_url = st.text_input("Enter the video link:")
85
+ analyze_video_clicked = st.button("Analyze Video")
86
+
87
+ if analyze_video_clicked:
88
  if not video_url.strip():
89
  st.warning("Please enter a valid video link.")
90
  else:
 
91
  result, accuracy = check_video_fake_news(video_url)
92
+ st.session_state["video_result"] = result
93
+ st.session_state["video_accuracy"] = accuracy
94
+ st.session_state["video_url"] = video_url # Store Video URL for Display
95
 
96
  # πŸ”Ή Results Section
97
  st.subheader("πŸ“Š Analysis Results")
98
+
99
+ # πŸ”Ή Text Result
100
+ if "text_result" in st.session_state:
101
+ result = st.session_state["text_result"]
102
+ accuracy = st.session_state["text_accuracy"]
103
 
104
  if result == "Fake":
105
+ st.error(f"❌ This news is **Fake**! (Accuracy: {accuracy}%)", icon="⚠️")
106
  else:
107
+ st.success(f"βœ… This news is **Real**! (Accuracy: {accuracy}%)", icon="βœ…")
108
+
109
+ verification_link = verify_news(news_text)
110
+ st.markdown(f"[πŸ”Ž Verify on Google]({verification_link})")
111
+
112
+ # πŸ”Ή Image Result
113
+ if "image_result" in st.session_state:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
  st.image(st.session_state["news_image"], caption="Uploaded Image", use_column_width=True)
115
+ st.info(f"πŸ–ΌοΈ **Image Analysis Result:** {st.session_state['image_result']} (Accuracy: {st.session_state['image_accuracy']}%)")
116
 
117
+ # πŸ”Ή Video Result
118
+ if "video_result" in st.session_state:
119
  st.video(st.session_state["video_url"])
120
+ st.info(f"πŸŽ₯ **Video Analysis Result:** {st.session_state['video_result']} (Accuracy: {st.session_state['video_accuracy']}%)")
121
+