Spaces:
Sleeping
Sleeping
added the sources classifier
Browse files
app.py
CHANGED
@@ -1,17 +1,50 @@
|
|
1 |
import gradio as gr
|
2 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
3 |
|
4 |
-
|
5 |
search_tool = DuckDuckGoSearchTool()
|
6 |
model = HfApiModel(model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/")
|
7 |
agent = CodeAgent(model=model, tools=[search_tool])
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
def detect_fake_news(news_text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
response = agent.run(f"Check if this news is true or fake: {news_text}")
|
12 |
-
return response
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
15 |
interface = gr.Interface(
|
16 |
fn=detect_fake_news,
|
17 |
inputs="text",
|
@@ -20,6 +53,6 @@ interface = gr.Interface(
|
|
20 |
description="Paste a news article or statement and get a credibility analysis"
|
21 |
)
|
22 |
|
23 |
-
|
24 |
if __name__ == "__main__":
|
25 |
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
3 |
|
4 |
+
|
5 |
search_tool = DuckDuckGoSearchTool()
|
6 |
model = HfApiModel(model_id="https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud/")
|
7 |
agent = CodeAgent(model=model, tools=[search_tool])
|
8 |
|
9 |
+
|
10 |
+
trusted_sources = [
|
11 |
+
"bbc.com", "reuters.com", "apnews.com", "nytimes.com",
|
12 |
+
"cnn.com", "forbes.com", "theguardian.com", "npr.org"
|
13 |
+
]
|
14 |
+
|
15 |
+
|
16 |
+
def classify_sources(search_results):
|
17 |
+
categorized_results = []
|
18 |
+
|
19 |
+
for result in search_results:
|
20 |
+
source_domain = result['url'].split('/')[2]
|
21 |
+
|
22 |
+
if source_domain in trusted_sources:
|
23 |
+
status = "✅ Trusted Source"
|
24 |
+
else:
|
25 |
+
status = "⚠️ Unverified Source"
|
26 |
+
|
27 |
+
categorized_results.append(f"{status}: [{result['title']}]({result['url']}) ({source_domain})")
|
28 |
+
|
29 |
+
return "\n".join(categorized_results)
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
def detect_fake_news(news_text):
|
34 |
+
|
35 |
+
search_results = search_tool.run(news_text)
|
36 |
+
|
37 |
+
|
38 |
+
sources_classification = classify_sources(search_results)
|
39 |
+
|
40 |
+
|
41 |
response = agent.run(f"Check if this news is true or fake: {news_text}")
|
|
|
42 |
|
43 |
+
|
44 |
+
return f"{response}\n\n🔍 **Source Analysis:**\n{sources_classification}"
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
interface = gr.Interface(
|
49 |
fn=detect_fake_news,
|
50 |
inputs="text",
|
|
|
53 |
description="Paste a news article or statement and get a credibility analysis"
|
54 |
)
|
55 |
|
56 |
+
|
57 |
if __name__ == "__main__":
|
58 |
interface.launch()
|