Nimzi commited on
Commit
81a136d
Β·
verified Β·
1 Parent(s): 62c311b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -10
app.py CHANGED
@@ -1,13 +1,23 @@
1
  import streamlit as st
2
  import os
 
 
 
 
 
 
3
  from groq import Groq
 
4
 
5
  # Set up the Groq client
6
- client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
 
 
 
7
 
8
  # Streamlit UI
9
  st.set_page_config(page_title="Fake News Detector", layout="centered")
10
- st.title("πŸ“° Fake News Detector")
11
 
12
  # User input
13
  news_text = st.text_area("Enter the news content to check:", height=200)
@@ -17,21 +27,23 @@ if st.button("Analyze News"):
17
  st.warning("Please enter some text.")
18
  else:
19
  with st.spinner("Analyzing..."):
20
- # Send request to Groq API
21
  chat_completion = client.chat.completions.create(
22
  messages=[{"role": "user", "content": f"Classify this news as Real or Fake: {news_text}"}],
23
  model="llama-3.3-70b-versatile",
24
  stream=False,
25
  )
26
- result = chat_completion.choices[0].message.content.strip().lower()
27
-
28
- # Display results with color contrast
29
- if "fake" in result:
30
- st.error("❌ This news is likely **Fake**!", icon="⚠️")
 
 
 
31
  st.markdown('<style>div.stAlert {background-color: #ffdddd;}</style>', unsafe_allow_html=True)
32
- elif "real" in result:
33
  st.success("βœ… This news is likely **Real**!", icon="βœ…")
34
  st.markdown('<style>div.stAlert {background-color: #ddffdd;}</style>', unsafe_allow_html=True)
35
  else:
36
  st.info("πŸ€” The result is uncertain. Please verify from trusted sources.")
37
-
 
1
  import streamlit as st
2
  import os
3
+ import cv2
4
+ import torch
5
+ import torchaudio
6
+ import torchvision
7
+ import tensorflow as tf
8
+ from transformers import pipeline
9
  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)
 
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.")