Spaces:
Sleeping
Sleeping
Clement Vachet
commited on
Commit
·
a1a1640
1
Parent(s):
3951659
Add requests arguments for encoding and headers
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ def retrieve_api():
|
|
30 |
|
31 |
#@spaces.GPU
|
32 |
def detect(image_path, model_id, threshold):
|
33 |
-
print("\n Object detection...")
|
34 |
print("\t ML model:", list_models[model_id])
|
35 |
|
36 |
with open(image_path, 'rb') as image_file:
|
@@ -46,10 +46,12 @@ 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 |
-
#
|
50 |
payload = {
|
51 |
-
'body': encoded_image
|
|
|
52 |
}
|
|
|
53 |
|
54 |
# Prepare the query string parameters
|
55 |
model_name = list_models_simple[model_id]
|
@@ -57,7 +59,8 @@ def detect(image_path, model_id, threshold):
|
|
57 |
'model': model_name
|
58 |
}
|
59 |
|
60 |
-
response = requests.post(API_endpoint, json=payload,
|
|
|
61 |
|
62 |
if response.status_code == 200:
|
63 |
# Process the response
|
|
|
30 |
|
31 |
#@spaces.GPU
|
32 |
def detect(image_path, model_id, threshold):
|
33 |
+
print("\n Gradio - Object detection...")
|
34 |
print("\t ML model:", list_models[model_id])
|
35 |
|
36 |
with open(image_path, 'rb') as image_file:
|
|
|
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]
|
|
|
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
|