Spaces:
Running
Running
Update app.py
Browse files
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("
|
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="
|
20 |
-
st.title("
|
21 |
-
|
22 |
-
#
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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!")
|