Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,41 +4,53 @@ from google import genai
|
|
| 4 |
from google.genai.types import GenerateContentConfig, GoogleSearch, Tool
|
| 5 |
|
| 6 |
# Initialize GenAI Client
|
| 7 |
-
API_KEY = os.getenv("GOOGLE_API_KEY") #
|
| 8 |
client = genai.Client(api_key=API_KEY)
|
| 9 |
-
MODEL_ID = "gemini-2.0-flash"
|
| 10 |
|
| 11 |
-
def
|
| 12 |
try:
|
| 13 |
-
#
|
| 14 |
google_search_tool = Tool(google_search=GoogleSearch())
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
response = client.models.generate_content(
|
| 18 |
model=MODEL_ID,
|
| 19 |
-
contents=
|
| 20 |
config=GenerateContentConfig(tools=[google_search_tool]),
|
| 21 |
)
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
-
return ai_response, search_results
|
| 28 |
except Exception as e:
|
| 29 |
return f"Error: {str(e)}", ""
|
| 30 |
|
| 31 |
# Gradio Interface
|
| 32 |
app = gr.Interface(
|
| 33 |
-
fn=
|
| 34 |
-
inputs=gr.Textbox(lines=
|
| 35 |
outputs=[
|
| 36 |
-
gr.Textbox(label="AI
|
| 37 |
-
gr.HTML(label="
|
| 38 |
],
|
| 39 |
-
title="
|
| 40 |
-
description="
|
| 41 |
)
|
| 42 |
|
| 43 |
if __name__ == "__main__":
|
| 44 |
-
app.launch(share=True)
|
|
|
|
| 4 |
from google.genai.types import GenerateContentConfig, GoogleSearch, Tool
|
| 5 |
|
| 6 |
# Initialize GenAI Client
|
| 7 |
+
API_KEY = os.getenv("GOOGLE_API_KEY") # Hugging Face Secrets
|
| 8 |
client = genai.Client(api_key=API_KEY)
|
| 9 |
+
MODEL_ID = "gemini-2.0-flash"
|
| 10 |
|
| 11 |
+
def fact_check_claim(claim):
|
| 12 |
try:
|
| 13 |
+
# Google Search Tool
|
| 14 |
google_search_tool = Tool(google_search=GoogleSearch())
|
| 15 |
+
|
| 16 |
+
prompt = f"""
|
| 17 |
+
You are a fact-checking assistant.
|
| 18 |
+
Analyze the following claim and decide whether it is:
|
| 19 |
+
- True
|
| 20 |
+
- False
|
| 21 |
+
- Misleading
|
| 22 |
+
|
| 23 |
+
Then give a short explanation based on reliable sources.
|
| 24 |
+
|
| 25 |
+
Claim:
|
| 26 |
+
{claim}
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
response = client.models.generate_content(
|
| 30 |
model=MODEL_ID,
|
| 31 |
+
contents=prompt,
|
| 32 |
config=GenerateContentConfig(tools=[google_search_tool]),
|
| 33 |
)
|
| 34 |
|
| 35 |
+
ai_analysis = response.text
|
| 36 |
+
sources_html = response.candidates[0].grounding_metadata.search_entry_point.rendered_content
|
| 37 |
+
|
| 38 |
+
return ai_analysis, sources_html
|
| 39 |
|
|
|
|
| 40 |
except Exception as e:
|
| 41 |
return f"Error: {str(e)}", ""
|
| 42 |
|
| 43 |
# Gradio Interface
|
| 44 |
app = gr.Interface(
|
| 45 |
+
fn=fact_check_claim,
|
| 46 |
+
inputs=gr.Textbox(lines=3, label="Enter a claim or news statement"),
|
| 47 |
outputs=[
|
| 48 |
+
gr.Textbox(label="AI Fact Check Result"),
|
| 49 |
+
gr.HTML(label="Sources & Evidence"),
|
| 50 |
],
|
| 51 |
+
title="AI Fact Checker with Gemini",
|
| 52 |
+
description="Enter a claim or news statement. The AI will verify it using Google search and provide evidence-based analysis.",
|
| 53 |
)
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
+
app.launch(share=True)
|