Nimzi commited on
Commit
7e55fba
Β·
verified Β·
1 Parent(s): a78610b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -32
app.py CHANGED
@@ -10,40 +10,66 @@ from groq import Groq
10
  from openai import OpenAI
11
 
12
  # Set up the Groq client
13
- client = Groq(api_key=os.environ.get("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"))
14
 
15
  # Load a fake news detection model from Hugging Face
16
  fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
17
 
18
  # Streamlit UI
19
- st.set_page_config(page_title="Fake News Detector", layout="centered")
20
- st.title("\U0001F4F0 Fake News Detector")
21
-
22
- # User input
23
- news_text = st.text_area("Enter the news content to check:", height=200)
24
-
25
- if st.button("Analyze News"):
26
- if not news_text.strip():
27
- st.warning("Please enter some text.")
28
- else:
29
- with st.spinner("Analyzing..."):
30
- # Check using Groq API
31
- chat_completion = client.chat.completions.create(
32
- messages=[{"role": "user", "content": f"Classify this news as Real or Fake: {news_text}"}],
33
- model="llama-3.3-70b-versatile",
34
- stream=False,
35
- )
36
- groq_result = chat_completion.choices[0].message.content.strip().lower()
37
-
38
- # Check using Hugging Face model
39
- hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
40
-
41
- # Determine the final result
42
- if "fake" in groq_result or hf_result == "fake":
43
- st.error("\u274C This news is likely **Fake**!", icon="⚠️")
44
- st.markdown('<style>div.stAlert {background-color: #ffdddd;}</style>', unsafe_allow_html=True)
45
- elif "real" in groq_result or hf_result == "real":
46
- st.success("βœ… This news is likely **Real**!", icon="βœ…")
47
- st.markdown('<style>div.stAlert {background-color: #ddffdd;}</style>', unsafe_allow_html=True)
48
- else:
49
- st.info("πŸ€” The result is uncertain. Please verify from trusted sources.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  from openai import OpenAI
11
 
12
  # Set up the Groq client
13
+ client = Groq(api_key=os.environ.get("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"))
14
 
15
  # Load a fake news detection model from Hugging Face
16
  fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
17
 
18
  # Streamlit UI
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!")