alessandro trinca tornidor commited on
Commit
55adef5
·
1 Parent(s): 81306d4

refactor: remove unused routes /post_test_dictlist, /post_test_string, /infer_samgis

Browse files
Files changed (1) hide show
  1. app.py +0 -61
app.py CHANGED
@@ -86,18 +86,6 @@ async def request_middleware(request, call_next):
86
  return response
87
 
88
 
89
- @app.post("/post_test_dictlist")
90
- def post_test_dictlist2(request_input: ApiRequestBody) -> JSONResponse:
91
- from samgis_lisa_on_zero.io_package.wrappers_helpers import get_parsed_bbox_points_with_dictlist_prompt
92
-
93
- request_body = get_parsed_bbox_points_with_dictlist_prompt(request_input)
94
- app_logger.info(f"request_body:{request_body}.")
95
- return JSONResponse(
96
- status_code=200,
97
- content=request_body
98
- )
99
-
100
-
101
  @app.get("/health")
102
  async def health() -> JSONResponse:
103
  import importlib.metadata
@@ -119,21 +107,6 @@ async def health() -> JSONResponse:
119
  return JSONResponse(status_code=200, content={"msg": "still alive..."})
120
 
121
 
122
- @app.post("/post_test_string")
123
- def post_test_string(request_input: StringPromptApiRequestBody) -> JSONResponse:
124
- from lisa_on_cuda.utils import app_helpers
125
- from samgis_lisa_on_zero.io_package.wrappers_helpers import get_parsed_bbox_points_with_string_prompt
126
-
127
- request_body = get_parsed_bbox_points_with_string_prompt(request_input)
128
- app_logger.info(f"request_body:{request_body}.")
129
- custom_args = app_helpers.parse_args([])
130
- request_body["content"] = {**request_body, "precision": str(custom_args.precision)}
131
- return JSONResponse(
132
- status_code=200,
133
- content=request_body
134
- )
135
-
136
-
137
  def infer_lisa_gradio(request_input: StringPromptApiRequestBody) -> JSONResponse:
138
  from samgis_lisa_on_zero.io_package.wrappers_helpers import get_parsed_bbox_points_with_string_prompt, get_source_name
139
  from samgis_lisa_on_zero.prediction_api import lisa
@@ -183,40 +156,6 @@ def infer_lisa(request_input: StringPromptApiRequestBody) -> JSONResponse:
183
  return JSONResponse(status_code=200, content={"body": dumped})
184
 
185
 
186
- @app.post("/infer_samgis")
187
- def infer_samgis(request_input: ApiRequestBody) -> JSONResponse:
188
- from samgis_lisa_on_zero.prediction_api import predictors
189
- from samgis_lisa_on_zero.io_package.wrappers_helpers import get_parsed_bbox_points_with_dictlist_prompt, get_source_name
190
-
191
- app_logger.info("starting plain samgis inference request...")
192
-
193
- try:
194
- import time
195
-
196
- time_start_run = time.time()
197
- body_request = get_parsed_bbox_points_with_dictlist_prompt(request_input)
198
- app_logger.info(f"body_request:{body_request}.")
199
- try:
200
- source_name = body_request["source_name"]
201
- app_logger.info(f"source_name = {source_name}.")
202
- output = predictors.samexporter_predict(
203
- bbox=body_request["bbox"], prompt=body_request["prompt"], zoom=body_request["zoom"],
204
- source=body_request["source"], source_name=source_name
205
- )
206
- duration_run = time.time() - time_start_run
207
- app_logger.info(f"duration_run:{duration_run}.")
208
- body = {
209
- "duration_run": duration_run,
210
- "output": output
211
- }
212
- return JSONResponse(status_code=200, content={"body": json.dumps(body)})
213
- except Exception as inference_exception:
214
- handle_exception_response(inference_exception)
215
- except ValidationError as va1:
216
- app_logger.error(f"validation error: {str(va1)}.")
217
- raise ValidationError("Unprocessable Entity")
218
-
219
-
220
  @app.exception_handler(RequestValidationError)
221
  async def request_validation_exception_handler(request: Request, exc: RequestValidationError) -> JSONResponse:
222
  app_logger.error(f"exception errors: {exc.errors()}.")
 
86
  return response
87
 
88
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  @app.get("/health")
90
  async def health() -> JSONResponse:
91
  import importlib.metadata
 
107
  return JSONResponse(status_code=200, content={"msg": "still alive..."})
108
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  def infer_lisa_gradio(request_input: StringPromptApiRequestBody) -> JSONResponse:
111
  from samgis_lisa_on_zero.io_package.wrappers_helpers import get_parsed_bbox_points_with_string_prompt, get_source_name
112
  from samgis_lisa_on_zero.prediction_api import lisa
 
156
  return JSONResponse(status_code=200, content={"body": dumped})
157
 
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  @app.exception_handler(RequestValidationError)
160
  async def request_validation_exception_handler(request: Request, exc: RequestValidationError) -> JSONResponse:
161
  app_logger.error(f"exception errors: {exc.errors()}.")