Spaces:
Sleeping
Sleeping
File size: 1,850 Bytes
b50ad18 9c881b4 b50ad18 70d18fa 9c881b4 d50305e 9c881b4 b50ad18 70d18fa 3fd573f 70d18fa 3fd573f 70d18fa 3fd573f 70d18fa 9c881b4 70d18fa 3fd573f 70d18fa 3fd573f 70d18fa 9c881b4 70d18fa 3fd573f 70d18fa 9c881b4 a65cd9e 9c881b4 70d18fa 9c881b4 70d18fa |
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 58 59 60 |
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()
|