Spaces:
Build error
Build error
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() | |
async def read_data(): | |
return df.to_dict(orient='records') | |
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 | |