Johnyquest7 commited on
Commit
724953a
·
verified ·
1 Parent(s): b6d30d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -43,10 +43,14 @@ def pubmed_search(mesh_terms, email, start_date, end_date):
43
  return "Please provide MeSH terms and email.", None, None
44
 
45
  # Join MeSH terms for query
46
- query = " AND ".join([f'"{term}"[MeSH Terms]' for term in mesh_terms])
 
 
 
 
47
 
48
  # Fetch PubMed IDs
49
- pubmed_ids = fetch_pubmed(query, email, start_date, end_date)
50
  if not pubmed_ids:
51
  return "No articles found for the given search terms and date range.", None, None
52
 
@@ -76,8 +80,8 @@ with gr.Blocks() as app:
76
  add_button = gr.Button("Add MeSH Term")
77
  mesh_terms_box = gr.Textbox(label="Added MeSH Terms", interactive=False, lines=2)
78
 
79
- start_date = gr.Date(label="Start Date")
80
- end_date = gr.Date(label="End Date")
81
  email_input = gr.Textbox(label="Email", placeholder="Your email (required by PubMed API)", interactive=True)
82
 
83
  search_button = gr.Button("Search PubMed")
@@ -89,14 +93,18 @@ with gr.Blocks() as app:
89
  # Logic for adding MeSH terms
90
  def add_mesh_term(term, terms):
91
  if term.strip():
92
- terms = terms.split(",") if terms else []
93
- terms.append(term.strip())
94
- return ", ".join(terms)
95
  return terms
96
 
97
  # Bind functions to interface
98
  add_button.click(fn=add_mesh_term, inputs=[mesh_term_input, mesh_terms_box], outputs=mesh_terms_box)
99
- search_button.click(fn=pubmed_search, inputs=[mesh_terms_box, email_input, start_date, end_date], outputs=[status_output, markdown_file, text_file])
 
 
 
 
100
 
101
  # Launch app
102
  app.launch()
 
43
  return "Please provide MeSH terms and email.", None, None
44
 
45
  # Join MeSH terms for query
46
+ query = " AND ".join([f'"{term}"[MeSH Terms]' for term in mesh_terms.split(", ")])
47
+
48
+ # Format the start and end dates
49
+ start_date_str = start_date.strftime("%Y/%m/%d %H:%M:%S")
50
+ end_date_str = end_date.strftime("%Y/%m/%d %H:%M:%S")
51
 
52
  # Fetch PubMed IDs
53
+ pubmed_ids = fetch_pubmed(query, email, start_date_str, end_date_str)
54
  if not pubmed_ids:
55
  return "No articles found for the given search terms and date range.", None, None
56
 
 
80
  add_button = gr.Button("Add MeSH Term")
81
  mesh_terms_box = gr.Textbox(label="Added MeSH Terms", interactive=False, lines=2)
82
 
83
+ start_date = gr.DateTime(label="Start Date and Time")
84
+ end_date = gr.DateTime(label="End Date and Time")
85
  email_input = gr.Textbox(label="Email", placeholder="Your email (required by PubMed API)", interactive=True)
86
 
87
  search_button = gr.Button("Search PubMed")
 
93
  # Logic for adding MeSH terms
94
  def add_mesh_term(term, terms):
95
  if term.strip():
96
+ terms_list = terms.split(", ") if terms else []
97
+ terms_list.append(term.strip())
98
+ return ", ".join(terms_list)
99
  return terms
100
 
101
  # Bind functions to interface
102
  add_button.click(fn=add_mesh_term, inputs=[mesh_term_input, mesh_terms_box], outputs=mesh_terms_box)
103
+ search_button.click(
104
+ fn=pubmed_search,
105
+ inputs=[mesh_terms_box, email_input, start_date, end_date],
106
+ outputs=[status_output, markdown_file, text_file]
107
+ )
108
 
109
  # Launch app
110
  app.launch()