Spaces:
Build error
Build error
File size: 1,072 Bytes
b731d10 |
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 |
from fastapi import FastAPI
import pandas as pd
from typing import List
from fastapi import FastAPI, HTTPException
import os
from services.location_services import LocationDataHandler
app = FastAPI()
# Initialize your LocationDataHandler
data_file = 'address.json'
df = pd.read_json(data_file).drop('embeddings_specialization', axis=1).dropna().reset_index().drop('index', axis=1)
handler = LocationDataHandler(df)
app = FastAPI()
@app.get("/data")
async def read_data():
return df.to_dict(orient='records')
@app.get("/filter_by_address")
async def api_filter_by_address(address: str, max_distance_km: float = 30):
try:
filtered_df = handler.filter_by_address(address, max_distance_km)
if filtered_df is not None:
return filtered_df.to_dict(orient='records')
else:
raise HTTPException(status_code=404, detail="No locations found within the specified distance")
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
# To run the server:
# uvicorn your_file_name:app --reload
|