Ubik80 commited on
Commit
70d18fa
Β·
1 Parent(s): 3fd573f

fixed search_tool method

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -1,23 +1,23 @@
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"
@@ -29,22 +29,22 @@ def classify_sources(search_results):
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,6 +53,7 @@ interface = gr.Interface(
53
  description="Paste a news article or statement and get a credibility analysis"
54
  )
55
 
56
-
57
  if __name__ == "__main__":
58
  interface.launch()
 
 
1
  import gradio as gr
2
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
3
 
4
+ # Inizializza il modello e l'agente
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
+ # Lista delle fonti affidabili
10
  trusted_sources = [
11
  "bbc.com", "reuters.com", "apnews.com", "nytimes.com",
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['url'].split('/')[2] # Estrai il dominio
21
 
22
  if source_domain in trusted_sources:
23
  status = "βœ… Trusted Source"
 
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,
50
  inputs="text",
 
53
  description="Paste a news article or statement and get a credibility analysis"
54
  )
55
 
56
+ # Avvio dell'app
57
  if __name__ == "__main__":
58
  interface.launch()
59
+