File size: 648 Bytes
eeeea78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
import sys
import os
import json
import requests

def main():
	img_path = sys.argv[1] if len(sys.argv) > 1 else 'test.jpg'
	url = 'http://127.0.0.1:5000/api/predict'

	if not os.path.exists(img_path):
		print(f"File not found: {img_path}")
		return

	try:
		with open(img_path, 'rb') as f:
			files = {'file': f}
			resp = requests.post(url, files=files)

		print(f'Status code: {resp.status_code}')
		try:
			print(json.dumps(resp.json(), indent=2))
		except Exception:
			print(resp.text)

	except requests.exceptions.ConnectionError as e:
		print('Connection error: Is the Flask server running?')
		print(e)


if __name__ == '__main__':
	main()