chatfed_whisp / utils /main_processor.py
leavoigt's picture
add preprocessing function
a576faa
raw
history blame contribute delete
799 Bytes
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