Shirish15 commited on
Commit
f26bcda
·
verified ·
1 Parent(s): df13da8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -82,35 +82,34 @@ def download_gbif_data(species_name, country_code, max_results):
82
  return error_message, None, None
83
 
84
 
 
 
 
 
 
 
 
 
 
 
85
  # Gradio Interface
86
  iface = gr.Interface(
87
- fn=download_gbif_data,
88
  inputs=[
89
  gr.Textbox(label="Species Name", placeholder="e.g. Aconitum naviculare"),
90
  gr.Textbox(label="Country Code", value="NP", placeholder="e.g. NP"),
91
  gr.Textbox(label="Max Results", value="5000", placeholder="e.g. 5000"),
92
  ],
93
  outputs=[
94
- gr.Textbox(label="Status"),
95
- gr.File(label="Download CSV"),
96
- gr.File(label="Download Metadata")
97
- ],
 
98
  title="GBIF Data Downloader",
99
  description="Enter a species name, country code, and max results to download CSV data from GBIF",
100
  )
101
 
102
- # Clean Up Temporary File
103
- def postprocess(status, csv_file_path, metadata_file_path):
104
- if csv_file_path:
105
- os.remove(csv_file_path)
106
- print (f"Removed temporary file: {csv_file_path}")
107
- if metadata_file_path:
108
- os.remove(metadata_file_path)
109
- print (f"Removed temporary file: {metadata_file_path}")
110
- return status, csv_file_path, metadata_file_path
111
-
112
- iface.config.postprocess = postprocess
113
-
114
  # Wrap the download_gbif_data function to convert max_result to int
115
  def download_gbif_data_wrapper(species_name, country_code, max_results):
116
  try:
@@ -119,7 +118,6 @@ def download_gbif_data_wrapper(species_name, country_code, max_results):
119
  return "Error: Invalid value for Max Results. Please enter a valid integer.", None, None
120
 
121
  return download_gbif_data(species_name, country_code, max_results)
122
- iface.wrap_fn = download_gbif_data_wrapper
123
 
124
 
125
  if __name__ == "__main__":
 
82
  return error_message, None, None
83
 
84
 
85
+ # Clean Up Temporary File
86
+ def postprocess(status, csv_file_path, metadata_file_path):
87
+ if csv_file_path:
88
+ os.remove(csv_file_path)
89
+ print(f"Removed temporary file: {csv_file_path}")
90
+ if metadata_file_path:
91
+ os.remove(metadata_file_path)
92
+ print(f"Removed temporary file: {metadata_file_path}")
93
+ return status, csv_file_path, metadata_file_path
94
+
95
  # Gradio Interface
96
  iface = gr.Interface(
97
+ fn=download_gbif_data_wrapper,
98
  inputs=[
99
  gr.Textbox(label="Species Name", placeholder="e.g. Aconitum naviculare"),
100
  gr.Textbox(label="Country Code", value="NP", placeholder="e.g. NP"),
101
  gr.Textbox(label="Max Results", value="5000", placeholder="e.g. 5000"),
102
  ],
103
  outputs=[
104
+ gr.Textbox(label="Status"),
105
+ gr.File(label="Download CSV"),
106
+ gr.File(label="Download Metadata"),
107
+ ],
108
+ postprocess=postprocess,
109
  title="GBIF Data Downloader",
110
  description="Enter a species name, country code, and max results to download CSV data from GBIF",
111
  )
112
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  # Wrap the download_gbif_data function to convert max_result to int
114
  def download_gbif_data_wrapper(species_name, country_code, max_results):
115
  try:
 
118
  return "Error: Invalid value for Max Results. Please enter a valid integer.", None, None
119
 
120
  return download_gbif_data(species_name, country_code, max_results)
 
121
 
122
 
123
  if __name__ == "__main__":