Spaces:
Sleeping
Sleeping
import gradio as gr | |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel | |
# Inizializza il modello e l'agente | |
search_tool = DuckDuckGoSearchTool() | |
model = HfApiModel(model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/") | |
agent = CodeAgent(model=model, tools=[search_tool]) | |
# Lista delle fonti affidabili | |
trusted_sources = [ | |
"bbc.com", "reuters.com", "apnews.com", "nytimes.com", | |
"cnn.com", "forbes.com", "theguardian.com", "npr.org" | |
] | |
# Funzione per classificare le fonti | |
def classify_sources(search_results): | |
categorized_results = [] | |
for result in search_results: | |
source_domain = result['url'].split('/')[2] # Estrai il dominio | |
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) | |
# Funzione principale per analizzare le notizie | |
def detect_fake_news(news_text): | |
# Cerca informazioni sulla notizia (CORRETTO!) | |
search_results = search_tool.invoke(news_text) | |
# Analizza le fonti | |
sources_classification = classify_sources(search_results) | |
# Interroga il modello LLM | |
response = agent.run(f"Check if this news is true or fake: {news_text}") | |
# Restituisci il risultato finale con analisi fonti | |
return f"{response}\n\nπ **Source Analysis:**\n{sources_classification}" | |
# Configurazione di Gradio | |
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" | |
) | |
# Avvio dell'app | |
if __name__ == "__main__": | |
interface.launch() | |