-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
executable file
·29 lines (23 loc) · 965 Bytes
/
test_app.py
File metadata and controls
executable file
·29 lines (23 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests
import base64
import concurrent.futures
import uuid
# Load and encode an image
with open("", "rb") as image_file: # give your image path here
encoded_string = base64.b64encode(image_file.read()).decode()
# Prepare the request payload
payload = {'image': encoded_string, "request_id": str(uuid.uuid4()), "task_type": "checkbox"}
# Function to send a POST request
def send_request():
try:
response = requests.post('http://127.0.0.1:5000/predict', json=payload)
print(f"Status Code: {response.status_code}")
predictions = response.json()
print(f"Response: {predictions}")
except Exception as e:
print(f"Request failed: {e}")
# Use ThreadPoolExecutor to send 10 requests in parallel
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
futures = [executor.submit(send_request) for _ in range(1)]
# Wait for all futures to complete
concurrent.futures.wait(futures)