-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgem.py
More file actions
31 lines (26 loc) · 978 Bytes
/
gem.py
File metadata and controls
31 lines (26 loc) · 978 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import google.generativeai as genai
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Configure Gemini with your API key
genai.configure(api_key=os.getenv('API_KEY'))
# Load the model
model = genai.GenerativeModel("gemini-2.5-flash")
def verify_post_with_gemini(post_content):
prompt = f"""You are a fact-checking AI assistant. Given the following post content,
respond with only `true` if the news seems likely to be true, or `false` if it seems fake.
Be concise and do not include explanations.
Post: "{post_content}"
Is this news likely true or fake? (Only respond `true` or `false`)
"""
try:
response = model.generate_content(prompt)
verdict = response.text.strip().lower()
if 'true' in verdict:
return True
elif 'false' in verdict:
return False
except Exception as e:
print("Gemini API Error:", e)
return None # In case of error