Clement Vachet commited on
Commit
6a10656
·
1 Parent(s): b062768

Add model type to API request

Browse files
Files changed (2) hide show
  1. app.py +3 -7
  2. lambda_function.py +5 -12
app.py CHANGED
@@ -46,21 +46,17 @@ def detect(image_path, model_id, threshold):
46
  # Encode the image data in base64
47
  encoded_image = base64.b64encode(image_bytes).decode('utf-8')
48
 
 
 
49
  # Requests arguments
50
  payload = {
51
  'body': encoded_image,
52
  'isBase64Encoded': True,
 
53
  }
54
  headers = {"Content-Type": "application/json"}
55
 
56
- # Prepare the query string parameters
57
- model_name = list_models_simple[model_id]
58
- params = {
59
- 'model': model_name
60
- }
61
-
62
  response = requests.post(API_endpoint, json=payload, headers=headers)
63
- # response = requests.post(API_endpoint, json=payload, headers=headers, params=params)
64
 
65
  if response.status_code == 200:
66
  # Process the response
 
46
  # Encode the image data in base64
47
  encoded_image = base64.b64encode(image_bytes).decode('utf-8')
48
 
49
+ model_name = list_models_simple[model_id]
50
+
51
  # Requests arguments
52
  payload = {
53
  'body': encoded_image,
54
  'isBase64Encoded': True,
55
+ 'model': model_name,
56
  }
57
  headers = {"Content-Type": "application/json"}
58
 
 
 
 
 
 
 
59
  response = requests.post(API_endpoint, json=payload, headers=headers)
 
60
 
61
  if response.status_code == 200:
62
  # Process the response
lambda_function.py CHANGED
@@ -40,18 +40,11 @@ def detection_pipeline(model_type, image_bytes):
40
  def lambda_handler(event, context):
41
  logger.info(f"API event: {event}")
42
  try:
43
- # Get the model name from the query string parameters
44
- # Condition for local testing
45
- # is_querystringparam = event.get('queryStringParameters')
46
- # if is_querystringparam is not None:
47
- # model_query = event['queryStringParameters'].get('model', '').lower()
48
- # else:
49
- # model_query = ""
50
- # model_type = get_model_type(model_query)
51
- # logger.info(f"Model query: {model_query}")
52
- # logger.info(f"Model type: {model_type}")
53
-
54
- model_type = get_model_type("")
55
 
56
  # Decode the base64-encoded image data from the event
57
  image_data = event['body']
 
40
  def lambda_handler(event, context):
41
  logger.info(f"API event: {event}")
42
  try:
43
+ # Retrieve model type
44
+ model_query = event.get('model', '')
45
+ model_type = get_model_type(model_query)
46
+ logger.info(f"Model query: {model_query}")
47
+ logger.info(f"Model type: {model_type}")
 
 
 
 
 
 
 
48
 
49
  # Decode the base64-encoded image data from the event
50
  image_data = event['body']