Nimzi commited on
Commit
f1dc8a7
Β·
verified Β·
1 Parent(s): dca5482

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -42
app.py CHANGED
@@ -4,7 +4,6 @@ from transformers import pipeline
4
  from PIL import Image
5
  import torch
6
  import torchvision.transforms as transforms
7
- import io
8
 
9
  # Load Fake News Detection Model from Hugging Face
10
  fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
@@ -28,43 +27,50 @@ def verify_news(news_text):
28
  st.set_page_config(page_title="Fake News Detector", layout="wide")
29
  st.title("πŸ“° Fake News Detector")
30
 
31
- # Ensure session state variables are initialized before modifying them
32
- for key in ["analyze_text", "result_text", "accuracy_text", "analyze_image", "analyze_video", "news_text", "news_image", "video_url"]:
33
- if key not in st.session_state:
34
- st.session_state[key] = None
35
 
36
- # Input Section
37
- st.header("1️⃣ Text Input")
38
- news_text = st.text_area("Enter the news content to check:", height=200)
39
- analyze_text_clicked = st.button("Analyze Text")
 
 
 
 
 
 
 
 
 
40
 
41
- if analyze_text_clicked and news_text.strip():
42
- result, accuracy = classify_text(news_text)
43
- st.session_state["news_text"] = news_text
44
- st.session_state["analyze_text"] = True
45
- st.session_state["result_text"] = result
46
- st.session_state["accuracy_text"] = accuracy
 
 
 
 
47
 
48
- st.header("2️⃣ Image Upload")
49
- uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
50
- analyze_image_clicked = st.button("Analyze Image")
51
-
52
- if uploaded_image and analyze_image_clicked:
53
- image = Image.open(uploaded_image)
54
- st.session_state["news_image"] = image
55
- st.session_state["analyze_image"] = True
56
-
57
- st.header("3️⃣ Video Link Input")
58
- video_url = st.text_input("Enter the video link:")
59
- analyze_video_clicked = st.button("Analyze Video")
60
-
61
- if analyze_video_clicked and video_url.strip():
62
- st.session_state["video_url"] = video_url
63
- st.session_state["analyze_video"] = True
64
 
65
  # Results Section
66
  st.subheader("πŸ“Š Analysis Results")
67
- if st.session_state.get("analyze_text", False):
68
  result = st.session_state.get("result_text")
69
  accuracy = st.session_state.get("accuracy_text")
70
  verification_link = verify_news(st.session_state.get("news_text"))
@@ -88,13 +94,3 @@ if st.session_state.get("analyze_text", False):
88
  for link in sources:
89
  st.markdown(f"[πŸ”— {link}]({link})")
90
  st.markdown(f"[πŸ”Ž Verify on Google]({verification_link})")
91
-
92
- if st.session_state.get("analyze_image", False):
93
- image = st.session_state.get("news_image")
94
- st.image(image, caption="Uploaded Image", use_column_width=True)
95
- st.info(analyze_image(image))
96
-
97
- if st.session_state.get("analyze_video", False):
98
- video_url = st.session_state.get("video_url", "")
99
- st.video(video_url)
100
- st.info("Video analysis feature coming soon!")
 
4
  from PIL import Image
5
  import torch
6
  import torchvision.transforms as transforms
 
7
 
8
  # Load Fake News Detection Model from Hugging Face
9
  fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
 
27
  st.set_page_config(page_title="Fake News Detector", layout="wide")
28
  st.title("πŸ“° Fake News Detector")
29
 
30
+ # Dividing Input Section
31
+ col1, col2, col3 = st.columns(3)
 
 
32
 
33
+ # Text Input Section
34
+ with col1:
35
+ st.subheader("πŸ“„ Enter Text")
36
+ news_text = st.text_area("Enter the news content to check:", height=150)
37
+ analyze_text_clicked = st.button("Analyze News")
38
+ if analyze_text_clicked:
39
+ if not news_text.strip():
40
+ st.warning("Please enter some text.")
41
+ else:
42
+ result, accuracy = classify_text(news_text)
43
+ st.session_state["news_text"] = news_text
44
+ st.session_state["result_text"] = result
45
+ st.session_state["accuracy_text"] = accuracy
46
 
47
+ # Image Upload Section
48
+ with col2:
49
+ st.subheader("πŸ–ΌοΈ Upload Image")
50
+ uploaded_image = st.file_uploader("Upload a news image", type=["jpg", "png", "jpeg"])
51
+ analyze_image_clicked = st.button("Analyze Image")
52
+ if uploaded_image and analyze_image_clicked:
53
+ image = Image.open(uploaded_image)
54
+ st.session_state["news_image"] = image
55
+ st.image(image, caption="Uploaded Image", use_column_width=True)
56
+ st.info(analyze_image(image))
57
 
58
+ # Video Link Input Section
59
+ with col3:
60
+ st.subheader("πŸŽ₯ Enter Video Link")
61
+ video_url = st.text_input("Enter the video link:")
62
+ analyze_video_clicked = st.button("Analyze Video")
63
+ if analyze_video_clicked:
64
+ if not video_url.strip():
65
+ st.warning("Please enter a valid video link.")
66
+ else:
67
+ st.session_state["video_url"] = video_url
68
+ st.video(video_url)
69
+ st.info("Video analysis feature coming soon!")
 
 
 
 
70
 
71
  # Results Section
72
  st.subheader("πŸ“Š Analysis Results")
73
+ if "result_text" in st.session_state:
74
  result = st.session_state.get("result_text")
75
  accuracy = st.session_state.get("accuracy_text")
76
  verification_link = verify_news(st.session_state.get("news_text"))
 
94
  for link in sources:
95
  st.markdown(f"[πŸ”— {link}]({link})")
96
  st.markdown(f"[πŸ”Ž Verify on Google]({verification_link})")