Ubik80's picture
added the sources classifier
3fd573f
raw
history blame
1.48 kB
import gradio as gr
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
search_tool = DuckDuckGoSearchTool()
model = HfApiModel(model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/")
agent = CodeAgent(model=model, tools=[search_tool])
trusted_sources = [
"bbc.com", "reuters.com", "apnews.com", "nytimes.com",
"cnn.com", "forbes.com", "theguardian.com", "npr.org"
]
def classify_sources(search_results):
categorized_results = []
for result in search_results:
source_domain = result['url'].split('/')[2]
if source_domain in trusted_sources:
status = "βœ… Trusted Source"
else:
status = "⚠️ Unverified Source"
categorized_results.append(f"{status}: [{result['title']}]({result['url']}) ({source_domain})")
return "\n".join(categorized_results)
def detect_fake_news(news_text):
search_results = search_tool.run(news_text)
sources_classification = classify_sources(search_results)
response = agent.run(f"Check if this news is true or fake: {news_text}")
return f"{response}\n\nπŸ” **Source Analysis:**\n{sources_classification}"
interface = gr.Interface(
fn=detect_fake_news,
inputs="text",
outputs="text",
title="πŸ•΅οΈ Fake News Detective",
description="Paste a news article or statement and get a credibility analysis"
)
if __name__ == "__main__":
interface.launch()