Spaces:
Running
Running
File size: 799 Bytes
5cd41bc a6dabb1 a576faa 5cd41bc a6dabb1 5cd41bc a576faa a6dabb1 a576faa 5cd41bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import json
import os
from utils.whisp_api_client import whisp_request
from utils.whisp_preprocessing import preprocess_whisp_data
# Import secrets
whisp_api_key = os.environ.get("WHISP_API_KEY")
# Define main function to fetch geojson, do API call and get statistics
def get_statistics(file):
# Open the geojson file uploaded
if file is None:
return "Geojson file empty"
try:
with open(file, 'r', encoding='utf-8') as f:
geojson_file = json.load(f)
except Exception as e:
return {"error": str(e)}
# Do the API call
whisp_response = whisp_request(geojson_file, api_key=whisp_api_key)
# Preprocess
preprocessed_response = preprocess_whisp_data(whisp_response)
# Do preprocessing
return preprocessed_response
|