UjjwalKGupta commited on
Commit
43ab29b
·
verified ·
1 Parent(s): ee32a0f
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -20,6 +20,11 @@ import xml.etree.ElementTree as ET
20
  from fastapi import FastAPI, HTTPException
21
  from urllib.parse import unquote
22
 
 
 
 
 
 
23
  # --- Helper Functions ---
24
 
25
  def one_time_setup():
@@ -366,10 +371,8 @@ def process_and_display(file_obj, url_str, buffer_m, progress=gr.Progress()):
366
  progress(1, desc="Done!")
367
  return m._repr_html_(), None, stats_df, dem_html, slope_html, geometry_json, buffer_geometry_json
368
 
369
- # Initialize the FastAPI app first
370
- app = FastAPI()
371
 
372
- @app.get("/api/geomtry")
373
  def calculate_geometry_metrics(request: FileUrlRequest):
374
  """
375
  Accepts a URL to a KML/GeoJSON file, calculates the area and perimeter
@@ -394,7 +397,6 @@ def calculate_geometry_metrics(request: FileUrlRequest):
394
  metric_gdf = to_best_crs(first_polygon_gdf)
395
 
396
  # 5. Calculate area and perimeter
397
- # .item() extracts the single value from the GeoSeries
398
  area_sq_meters = metric_gdf.area.item()
399
  perimeter_meters = metric_gdf.length.item()
400
 
 
20
  from fastapi import FastAPI, HTTPException
21
  from urllib.parse import unquote
22
 
23
+ class FileUrlRequest(BaseModel):
24
+ url: HttpUrl
25
+
26
+ app = FastAPI()
27
+
28
  # --- Helper Functions ---
29
 
30
  def one_time_setup():
 
371
  progress(1, desc="Done!")
372
  return m._repr_html_(), None, stats_df, dem_html, slope_html, geometry_json, buffer_geometry_json
373
 
 
 
374
 
375
+ @app.post("/api/geometry")
376
  def calculate_geometry_metrics(request: FileUrlRequest):
377
  """
378
  Accepts a URL to a KML/GeoJSON file, calculates the area and perimeter
 
397
  metric_gdf = to_best_crs(first_polygon_gdf)
398
 
399
  # 5. Calculate area and perimeter
 
400
  area_sq_meters = metric_gdf.area.item()
401
  perimeter_meters = metric_gdf.length.item()
402