mabil commited on
Commit
8b3c01e
·
1 Parent(s): cabbd61

Fix: Improved OUI calculation and report in English, added article scoring, and optimized article selection

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -89,10 +89,22 @@ def fetch_pubmed_details(article_id):
89
  response.raise_for_status()
90
  import xml.etree.ElementTree as ET
91
  root = ET.fromstring(response.text)
92
- title = root.find(".//ArticleTitle").text if root.find(".//ArticleTitle") is not None else "No Title"
93
- abstract = root.find(".//AbstractText").text if root.find(".//AbstractText") is not None else "No Abstract"
 
 
 
 
 
 
 
 
 
 
 
94
  keywords = root.findall(".//Keyword")
95
  keyword_text = " ".join([kw.text for kw in keywords if kw.text]) if keywords else ""
 
96
  return title, f"{abstract} {keyword_text}"
97
  except Exception as e:
98
  print(f"Errore recupero abstract: {e}")
@@ -154,7 +166,7 @@ def validate():
154
  pubmed_ids = fetch_pubmed(query, year_start, year_end, num_articles)
155
 
156
  if not pubmed_ids:
157
- flash("Nessun articolo trovato su PubMed per questa ricerca.", "error")
158
  return redirect(url_for("index"))
159
 
160
  pubmed_results = [fetch_pubmed_details(id_) for id_ in pubmed_ids]
@@ -213,4 +225,4 @@ def download_report():
213
  return send_file(output_path, as_attachment=True)
214
 
215
  if __name__ == "__main__":
216
- app.run(debug=True, host="0.0.0.0", port=7860)
 
89
  response.raise_for_status()
90
  import xml.etree.ElementTree as ET
91
  root = ET.fromstring(response.text)
92
+
93
+ title_elem = root.find(".//ArticleTitle")
94
+ abstract_elem = root.find(".//AbstractText")
95
+
96
+ # Gestire caso in cui titolo o abstract non siano presenti
97
+ title = title_elem.text if title_elem is not None else None
98
+ abstract = abstract_elem.text if abstract_elem is not None else None
99
+
100
+ if not title or not abstract:
101
+ # Se manca titolo o abstract, restituisci un messaggio chiaro
102
+ return "No Title", "No Abstract"
103
+
104
+ # Recupero delle parole chiave
105
  keywords = root.findall(".//Keyword")
106
  keyword_text = " ".join([kw.text for kw in keywords if kw.text]) if keywords else ""
107
+
108
  return title, f"{abstract} {keyword_text}"
109
  except Exception as e:
110
  print(f"Errore recupero abstract: {e}")
 
166
  pubmed_ids = fetch_pubmed(query, year_start, year_end, num_articles)
167
 
168
  if not pubmed_ids:
169
+ flash("Nessun articolo trovato su PubMed per questa ricerca.", "error")
170
  return redirect(url_for("index"))
171
 
172
  pubmed_results = [fetch_pubmed_details(id_) for id_ in pubmed_ids]
 
225
  return send_file(output_path, as_attachment=True)
226
 
227
  if __name__ == "__main__":
228
+ app.run(debug=True, host="0.0.0.0", port=7860)