Spaces:
Sleeping
Sleeping
fixes
Browse files
app.py
CHANGED
@@ -12,38 +12,37 @@ trusted_sources = [
|
|
12 |
"cnn.com", "forbes.com", "theguardian.com", "npr.org"
|
13 |
]
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
# Funzione per classificare le fonti
|
16 |
def classify_sources(search_results):
|
17 |
categorized_results = []
|
18 |
|
19 |
for result in search_results:
|
20 |
-
source_domain = result['
|
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['
|
28 |
|
29 |
return "\n".join(categorized_results)
|
30 |
|
31 |
-
|
32 |
-
# Funzione principale per analizzare le notizie
|
33 |
-
def detect_fake_news(news_text):
|
34 |
-
# Cerca informazioni sulla notizia (CORRETTO!)
|
35 |
-
search_results = search_tool.invoke(news_text)
|
36 |
-
|
37 |
-
# Analizza le fonti
|
38 |
-
sources_classification = classify_sources(search_results)
|
39 |
-
|
40 |
-
# Interroga il modello LLM
|
41 |
-
response = agent.run(f"Check if this news is true or fake: {news_text}")
|
42 |
-
|
43 |
-
# Restituisci il risultato finale con analisi fonti
|
44 |
-
return f"{response}\n\n๐ **Source Analysis:**\n{sources_classification}"
|
45 |
-
|
46 |
-
|
47 |
# Configurazione di Gradio
|
48 |
interface = gr.Interface(
|
49 |
fn=detect_fake_news,
|
@@ -57,3 +56,4 @@ interface = gr.Interface(
|
|
57 |
if __name__ == "__main__":
|
58 |
interface.launch()
|
59 |
|
|
|
|
12 |
"cnn.com", "forbes.com", "theguardian.com", "npr.org"
|
13 |
]
|
14 |
|
15 |
+
# Funzione per analizzare le notizie
|
16 |
+
def detect_fake_news(news_text):
|
17 |
+
# Esegui una ricerca sul web relativa al testo della notizia
|
18 |
+
search_results = search_tool(news_text)
|
19 |
+
|
20 |
+
# Classifica le fonti
|
21 |
+
sources_classification = classify_sources(search_results)
|
22 |
+
|
23 |
+
# Analizza la notizia utilizzando l'agente
|
24 |
+
response = agent.run(f"Check if this news is true or fake: {news_text}")
|
25 |
+
|
26 |
+
# Combina l'analisi dell'agente con la classificazione delle fonti
|
27 |
+
final_response = f"{response}\n\n๐ Source Analysis:\n{sources_classification}"
|
28 |
+
return final_response
|
29 |
+
|
30 |
# Funzione per classificare le fonti
|
31 |
def classify_sources(search_results):
|
32 |
categorized_results = []
|
33 |
|
34 |
for result in search_results:
|
35 |
+
source_domain = result['href'].split('/')[2] # Estrai il dominio dal link
|
36 |
|
37 |
if source_domain in trusted_sources:
|
38 |
status = "โ
Trusted Source"
|
39 |
else:
|
40 |
status = "โ ๏ธ Unverified Source"
|
41 |
|
42 |
+
categorized_results.append(f"{status}: [{result['title']}]({result['href']}) ({source_domain})")
|
43 |
|
44 |
return "\n".join(categorized_results)
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# Configurazione di Gradio
|
47 |
interface = gr.Interface(
|
48 |
fn=detect_fake_news,
|
|
|
56 |
if __name__ == "__main__":
|
57 |
interface.launch()
|
58 |
|
59 |
+
|