Nimzi commited on
Commit
62c311b
Β·
verified Β·
1 Parent(s): 4f33550

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)
14
+
15
+ if st.button("Analyze News"):
16
+ if not news_text.strip():
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
+