File size: 1,480 Bytes
b50ad18
9c881b4
b50ad18
3fd573f
9c881b4
d50305e
9c881b4
b50ad18
3fd573f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9c881b4
3fd573f
 
 
 
 
 
 
9c881b4
 
3fd573f
 
 
 
 
9c881b4
 
 
 
 
a65cd9e
9c881b4
 
3fd573f
9c881b4
 
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
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()