Nimzi commited on
Commit
873f8c6
Β·
verified Β·
1 Parent(s): 0e6d020

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -6,11 +6,6 @@ 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("GROQ_API_KEY"))
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")
@@ -46,7 +41,7 @@ with tab1:
46
  else:
47
  st.session_state["news_text"] = news_text
48
  st.session_state["analyze"] = True
49
- st.experimental_rerun()
50
 
51
  elif option == "Image":
52
  uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
@@ -66,23 +61,15 @@ with tab2:
66
  if st.session_state.get("analyze", False):
67
  news_text = st.session_state.get("news_text", "")
68
  with st.spinner("Analyzing..."):
69
- # Check using Groq API
70
- chat_completion = client.chat.completions.create(
71
- messages=[{"role": "user", "content": f"Classify this news as Real or Fake: {news_text}"}],
72
- model="llama-3.3-70b-versatile",
73
- stream=False,
74
- )
75
- groq_result = chat_completion.choices[0].message.content.strip().lower()
76
-
77
  # Check using Hugging Face model
78
  hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
79
 
80
  # Display result
81
- if "fake" in groq_result or hf_result == "fake":
82
  st.error("❌ This news is likely **Fake**!", icon="⚠️")
83
  st.markdown('<style>div.stAlert {background-color: #ffdddd;}</style>', unsafe_allow_html=True)
84
  conclusion = "The analysis suggests that this news might be fabricated or misleading. Please verify from credible sources."
85
- elif "real" in groq_result or hf_result == "real":
86
  st.success("βœ… This news is likely **Real**!", icon="βœ…")
87
  st.markdown('<style>div.stAlert {background-color: #ddffdd;}</style>', unsafe_allow_html=True)
88
  conclusion = "The analysis indicates that this news appears to be credible and factual."
@@ -97,4 +84,4 @@ with tab2:
97
  # Display real news sources
98
  st.subheader("πŸ”— Reliable News Sources")
99
  for link in fetch_real_news_links():
100
- st.markdown(f"[πŸ”— {link}]({link})")
 
6
  import torchvision
7
  import tensorflow as tf
8
  from transformers import pipeline
 
 
 
 
 
9
 
10
  # Load a fake news detection model from Hugging Face
11
  fake_news_pipeline = pipeline("text-classification", model="mrm8488/bert-tiny-finetuned-fake-news-detection")
 
41
  else:
42
  st.session_state["news_text"] = news_text
43
  st.session_state["analyze"] = True
44
+ st.rerun()
45
 
46
  elif option == "Image":
47
  uploaded_file = st.file_uploader("Upload an image of a news article", type=["jpg", "png", "jpeg"])
 
61
  if st.session_state.get("analyze", False):
62
  news_text = st.session_state.get("news_text", "")
63
  with st.spinner("Analyzing..."):
 
 
 
 
 
 
 
 
64
  # Check using Hugging Face model
65
  hf_result = fake_news_pipeline(news_text)[0]['label'].lower()
66
 
67
  # Display result
68
+ if hf_result == "fake":
69
  st.error("❌ This news is likely **Fake**!", icon="⚠️")
70
  st.markdown('<style>div.stAlert {background-color: #ffdddd;}</style>', unsafe_allow_html=True)
71
  conclusion = "The analysis suggests that this news might be fabricated or misleading. Please verify from credible sources."
72
+ elif hf_result == "real":
73
  st.success("βœ… This news is likely **Real**!", icon="βœ…")
74
  st.markdown('<style>div.stAlert {background-color: #ddffdd;}</style>', unsafe_allow_html=True)
75
  conclusion = "The analysis indicates that this news appears to be credible and factual."
 
84
  # Display real news sources
85
  st.subheader("πŸ”— Reliable News Sources")
86
  for link in fetch_real_news_links():
87
+ st.markdown(f"[πŸ”— {link}]({link})")