File size: 1,554 Bytes
35500cf
 
 
 
 
 
508a8e9
35500cf
508a8e9
35500cf
508a8e9
35500cf
508a8e9
35500cf
508a8e9
 
 
 
 
 
 
 
 
 
 
 
 
 
35500cf
 
508a8e9
35500cf
 
 
508a8e9
 
 
 
35500cf
 
 
 
 
 
508a8e9
 
35500cf
508a8e9
 
35500cf
508a8e9
 
35500cf
 
 
508a8e9
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import gradio as gr
from google import genai
from google.genai.types import GenerateContentConfig, GoogleSearch, Tool

# Initialize GenAI Client
API_KEY = os.getenv("GOOGLE_API_KEY")  # Hugging Face Secrets
client = genai.Client(api_key=API_KEY)
MODEL_ID = "gemini-2.0-flash"

def fact_check_claim(claim):
    try:
        # Google Search Tool
        google_search_tool = Tool(google_search=GoogleSearch())

        prompt = f"""
You are a fact-checking assistant.
Analyze the following claim and decide whether it is:
- True
- False
- Misleading

Then give a short explanation based on reliable sources.

Claim:
{claim}
"""

        response = client.models.generate_content(
            model=MODEL_ID,
            contents=prompt,
            config=GenerateContentConfig(tools=[google_search_tool]),
        )

        ai_analysis = response.text
        sources_html = response.candidates[0].grounding_metadata.search_entry_point.rendered_content

        return ai_analysis, sources_html

    except Exception as e:
        return f"Error: {str(e)}", ""

# Gradio Interface
app = gr.Interface(
    fn=fact_check_claim,
    inputs=gr.Textbox(lines=3, label="Enter a claim or news statement"),
    outputs=[
        gr.Textbox(label="AI Fact Check Result"),
        gr.HTML(label="Sources & Evidence"),
    ],
    title="AI Fact Checker with Gemini",
    description="Enter a claim or news statement. The AI will verify it using Google search and provide evidence-based analysis.",
)

if __name__ == "__main__":
    app.launch(share=True)