Spaces:
Sleeping
Sleeping
Johnyquest7
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -42,30 +42,19 @@ 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 |
# 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,
|
50 |
if not pubmed_ids:
|
51 |
return "No articles found for the given search terms and date range.", None, None
|
52 |
|
53 |
-
|
54 |
-
records = fetch_details(pubmed_ids)
|
55 |
-
if not records["PubmedArticle"]:
|
56 |
-
return "No detailed articles found.", None, None
|
57 |
-
|
58 |
-
# Compile summaries
|
59 |
-
markdown_content = compile_summaries(records)
|
60 |
-
text_content = markdown_content.replace("\n", "\r\n")
|
61 |
-
|
62 |
-
# Save files temporarily for download
|
63 |
-
with open("results.md", "w") as md_file:
|
64 |
-
md_file.write(markdown_content)
|
65 |
-
with open("results.txt", "w") as txt_file:
|
66 |
-
txt_file.write(text_content)
|
67 |
-
|
68 |
-
return "Search completed successfully. Download your files below.", "results.md", "results.txt"
|
69 |
|
70 |
# Gradio interface components
|
71 |
with gr.Blocks() as app:
|
@@ -76,8 +65,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.
|
80 |
-
end_date = gr.
|
81 |
email_input = gr.Textbox(label="Email", placeholder="Your email (required by PubMed API)", interactive=True)
|
82 |
|
83 |
search_button = gr.Button("Search PubMed")
|
|
|
42 |
if not mesh_terms or not email:
|
43 |
return "Please provide MeSH terms and email.", None, None
|
44 |
|
45 |
+
# Convert datetime objects to string format
|
46 |
+
start_date_str = start_date.strftime("%Y-%m-%d")
|
47 |
+
end_date_str = end_date.strftime("%Y-%m-%d")
|
48 |
+
|
49 |
# Join MeSH terms for query
|
50 |
query = " AND ".join([f'"{term}"[MeSH Terms]' for term in mesh_terms])
|
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 |
|
57 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Gradio interface components
|
60 |
with gr.Blocks() as app:
|
|
|
65 |
add_button = gr.Button("Add MeSH Term")
|
66 |
mesh_terms_box = gr.Textbox(label="Added MeSH Terms", interactive=False, lines=2)
|
67 |
|
68 |
+
start_date = gr.DateTime(label="Start Date", value="2025-01-01")
|
69 |
+
end_date = gr.DateTime(label="End Date", value="2025-01-07")
|
70 |
email_input = gr.Textbox(label="Email", placeholder="Your email (required by PubMed API)", interactive=True)
|
71 |
|
72 |
search_button = gr.Button("Search PubMed")
|