Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 880 Bytes
9965d08 e95771c 9965d08 150dbdb 9965d08 | 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 35 36 37 | 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")
print(f"API key loaded: {whisp_api_key is not None}")
# 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)
print(whisp_response)
# Preprocess
preprocessed_response = preprocess_whisp_data(whisp_response)
# Do preprocessing
return preprocessed_response
|