Shirish15 commited on
Commit
b421d8c
·
verified ·
1 Parent(s): 9545a51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -78,7 +78,6 @@ def download_gbif_data(species_name, country_code, max_results):
78
  print(error_message)
79
  return error_message, None, None
80
 
81
-
82
  # Clean Up Temporary File
83
  def postprocess(status, csv_file_path, metadata_file_path):
84
  if csv_file_path:
@@ -100,6 +99,7 @@ def download_gbif_data_wrapper(species_name, country_code, max_results):
100
  return download_gbif_data(species_name, country_code, max_results)
101
 
102
 
 
103
  # Gradio Interface using gr.Blocks
104
  with gr.Blocks(title="GBIF Data Downloader") as iface:
105
  gr.Markdown("Enter a species name, country code, and max results to download CSV data from GBIF")
@@ -107,6 +107,8 @@ with gr.Blocks(title="GBIF Data Downloader") as iface:
107
  species_name_input = gr.Textbox(label="Species Name", placeholder="e.g. Aconitum naviculare")
108
  country_code_input = gr.Textbox(label="Country Code", value="NP", placeholder="e.g. NP")
109
  max_results_input = gr.Textbox(label="Max Results", value="5000", placeholder="e.g. 5000")
 
 
110
  with gr.Row():
111
  output_status = gr.Textbox(label="Status")
112
  output_csv = gr.File(label="Download CSV")
@@ -115,12 +117,15 @@ with gr.Blocks(title="GBIF Data Downloader") as iface:
115
  inputs = [species_name_input, country_code_input, max_results_input]
116
  outputs = [output_status, output_csv, output_metadata]
117
 
118
- iface.load(
 
 
 
119
  download_gbif_data_wrapper,
120
  inputs=inputs,
121
  outputs=outputs,
122
  postprocess = postprocess
123
- )
124
 
125
  if __name__ == "__main__":
126
  iface.launch()
 
78
  print(error_message)
79
  return error_message, None, None
80
 
 
81
  # Clean Up Temporary File
82
  def postprocess(status, csv_file_path, metadata_file_path):
83
  if csv_file_path:
 
99
  return download_gbif_data(species_name, country_code, max_results)
100
 
101
 
102
+
103
  # Gradio Interface using gr.Blocks
104
  with gr.Blocks(title="GBIF Data Downloader") as iface:
105
  gr.Markdown("Enter a species name, country code, and max results to download CSV data from GBIF")
 
107
  species_name_input = gr.Textbox(label="Species Name", placeholder="e.g. Aconitum naviculare")
108
  country_code_input = gr.Textbox(label="Country Code", value="NP", placeholder="e.g. NP")
109
  max_results_input = gr.Textbox(label="Max Results", value="5000", placeholder="e.g. 5000")
110
+ with gr.Row():
111
+ download_button = gr.Button("Download Data")
112
  with gr.Row():
113
  output_status = gr.Textbox(label="Status")
114
  output_csv = gr.File(label="Download CSV")
 
117
  inputs = [species_name_input, country_code_input, max_results_input]
118
  outputs = [output_status, output_csv, output_metadata]
119
 
120
+ def clear_inputs(): # Create a function to clear all inputs
121
+ return [None, None, None]
122
+
123
+ download_button.click(
124
  download_gbif_data_wrapper,
125
  inputs=inputs,
126
  outputs=outputs,
127
  postprocess = postprocess
128
+ ).then(clear_inputs, None, inputs) # added the then() and clear_inputs
129
 
130
  if __name__ == "__main__":
131
  iface.launch()