File size: 1,933 Bytes
b50ad18
9c881b4
b50ad18
70d18fa
9c881b4
d50305e
9c881b4
b50ad18
70d18fa
3fd573f
 
 
 
 
aef296e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70d18fa
3fd573f
 
 
 
aef296e
3fd573f
 
 
 
 
 
aef296e
3fd573f
 
 
70d18fa
9c881b4
 
 
 
 
a65cd9e
9c881b4
 
70d18fa
9c881b4
 
70d18fa
aef296e
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 analizzare le notizie
def detect_fake_news(news_text):
    # Esegui una ricerca sul web relativa al testo della notizia
    search_results = search_tool(news_text)
    
    # Classifica le fonti
    sources_classification = classify_sources(search_results)
    
    # Analizza la notizia utilizzando l'agente
    response = agent.run(f"Check if this news is true or fake: {news_text}")
    
    # Combina l'analisi dell'agente con la classificazione delle fonti
    final_response = f"{response}\n\n๐Ÿ” Source Analysis:\n{sources_classification}"
    return final_response

# Funzione per classificare le fonti
def classify_sources(search_results):
    categorized_results = []
    
    for result in search_results:
        source_domain = result['href'].split('/')[2]  # Estrai il dominio dal link
        
        if source_domain in trusted_sources:
            status = "โœ… Trusted Source"
        else:
            status = "โš ๏ธ Unverified Source"
        
        categorized_results.append(f"{status}: [{result['title']}]({result['href']}) ({source_domain})")
    
    return "\n".join(categorized_results)

# 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()