Gaborandi commited on
Commit
cfd6947
·
1 Parent(s): 6f731ee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,17 +1,18 @@
1
  import logging
2
  import pandas as pd
3
  import gradio as gr
4
- import ipywidgets as widgets
5
  from pymed import PubMed
6
- from Bio import Entrez
 
 
7
 
8
- def search_pubmed(search_term, keywords, max_results):
9
  # Validate the input
10
- if max_results < 1:
11
  raise ValueError("Max Results must be a positive integer")
12
 
13
  # Connect to PubMed database
14
- pubmed = PubMed(tool="MyTool", email="aalamel@clemson.edu")
15
  results = pubmed.query(search_term, max_results=max_results)
16
 
17
  # Prepare the lists to store article information
@@ -48,6 +49,11 @@ def search_pubmed(search_term, keywords, max_results):
48
  def download_csv(b):
49
  download_button.description = "Downloading..."
50
  download_button.disabled = True
 
 
 
 
 
51
  dataframe.to_csv("pubmed_results.csv", index=False)
52
  download_button.description = "Download CSV"
53
  download_button.disabled = False
@@ -61,7 +67,6 @@ outputs = [gr.outputs.Dataframe(type="pandas")]
61
  interface = gr.Interface(search_pubmed, inputs, outputs, title="PubMed Search")
62
 
63
  result = interface.launch(share=True)
64
- dataframe = result[0]
65
 
66
  download_button = widgets.Button(description="Download CSV")
67
  download_button.on_click(download_csv)
 
1
  import logging
2
  import pandas as pd
3
  import gradio as gr
 
4
  from pymed import PubMed
5
+ import urllib.parse
6
+ import urllib.request
7
+ import ipywidgets as widgets
8
 
9
+ def search_pubmed(search_term, keywords, max_results, tool, email):
10
  # Validate the input
11
+ if max_results is None or max_results < 1:
12
  raise ValueError("Max Results must be a positive integer")
13
 
14
  # Connect to PubMed database
15
+ pubmed = PubMed(tool=tool, email=email)
16
  results = pubmed.query(search_term, max_results=max_results)
17
 
18
  # Prepare the lists to store article information
 
49
  def download_csv(b):
50
  download_button.description = "Downloading..."
51
  download_button.disabled = True
52
+ input_dict = interface.process(raw=False)
53
+ search_term = input_dict["Search Term"]
54
+ keywords = input_dict["Keywords"]
55
+ max_results = input_dict["Max Results"]
56
+ dataframe = search_pubmed(search_term, keywords, max_results)
57
  dataframe.to_csv("pubmed_results.csv", index=False)
58
  download_button.description = "Download CSV"
59
  download_button.disabled = False
 
67
  interface = gr.Interface(search_pubmed, inputs, outputs, title="PubMed Search")
68
 
69
  result = interface.launch(share=True)
 
70
 
71
  download_button = widgets.Button(description="Download CSV")
72
  download_button.on_click(download_csv)