Spaces:
Sleeping
Sleeping
Johnyquest7
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -42,18 +42,11 @@ def pubmed_search(mesh_terms, email, start_date, end_date):
|
|
42 |
if not mesh_terms or not email:
|
43 |
return "Please provide MeSH terms and email.", None, None
|
44 |
|
45 |
-
if start_date is None or end_date is None:
|
46 |
-
return "Please select both start and end dates.", None, None
|
47 |
-
|
48 |
# Join MeSH terms for query
|
49 |
-
query = " AND ".join([f'"{term}"[MeSH Terms]' for term in mesh_terms
|
50 |
-
|
51 |
-
# Format the start and end dates
|
52 |
-
start_date_str = start_date.strftime("%Y/%m/%d %H:%M:%S")
|
53 |
-
end_date_str = end_date.strftime("%Y/%m/%d %H:%M:%S")
|
54 |
|
55 |
# Fetch PubMed IDs
|
56 |
-
pubmed_ids = fetch_pubmed(query, email,
|
57 |
if not pubmed_ids:
|
58 |
return "No articles found for the given search terms and date range.", None, None
|
59 |
|
@@ -83,9 +76,8 @@ with gr.Blocks() as app:
|
|
83 |
add_button = gr.Button("Add MeSH Term")
|
84 |
mesh_terms_box = gr.Textbox(label="Added MeSH Terms", interactive=False, lines=2)
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
end_date = gr.DateTime(label="End Date and Time", value=datetime.now())
|
89 |
email_input = gr.Textbox(label="Email", placeholder="Your email (required by PubMed API)", interactive=True)
|
90 |
|
91 |
search_button = gr.Button("Search PubMed")
|
@@ -97,18 +89,14 @@ with gr.Blocks() as app:
|
|
97 |
# Logic for adding MeSH terms
|
98 |
def add_mesh_term(term, terms):
|
99 |
if term.strip():
|
100 |
-
|
101 |
-
|
102 |
-
return ", ".join(
|
103 |
return terms
|
104 |
|
105 |
# Bind functions to interface
|
106 |
add_button.click(fn=add_mesh_term, inputs=[mesh_term_input, mesh_terms_box], outputs=mesh_terms_box)
|
107 |
-
search_button.click(
|
108 |
-
fn=pubmed_search,
|
109 |
-
inputs=[mesh_terms_box, email_input, start_date, end_date],
|
110 |
-
outputs=[status_output, markdown_file, text_file]
|
111 |
-
)
|
112 |
|
113 |
# Launch app
|
114 |
app.launch()
|
|
|
42 |
if not mesh_terms or not email:
|
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 |
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.Textbox(label="Start Date (YYYY-MM-DD)", placeholder="e.g., 2025-01-01")
|
80 |
+
end_date = gr.Textbox(label="End Date (YYYY-MM-DD)", placeholder="e.g., 2025-01-07")
|
|
|
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 |
# 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()
|