Junathan Richie commited on
Commit
fc3eb6d
·
1 Parent(s): 5a16251

refactor: adjust python client example

Browse files
Files changed (1) hide show
  1. python_client.py +12 -1
python_client.py CHANGED
@@ -3,10 +3,21 @@ import base64
3
  from PIL import Image
4
  from io import BytesIO
5
  import matplotlib.pyplot as plt
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  with open('glioma.jpg', 'rb') as f:
8
  files = {'file': ('glioma.jpg', f, 'image/jpeg')}
9
- response = requests.post('http://localhost:8000/inference', files=files)
10
 
11
  result = response.json()
12
 
 
3
  from PIL import Image
4
  from io import BytesIO
5
  import matplotlib.pyplot as plt
6
+ import argparse
7
+ parser = argparse.ArgumentParser(description="Client for FastAPI image inference")
8
+ parser.add_argument("--env", '-e', type=str, default="local", help="Environment: local or deployed")
9
+ args = parser.parse_args()
10
+
11
+ if args.env == "local":
12
+ FASTAPI_URL = "http://localhost:8000"
13
+ elif args.env == "deployed":
14
+ FASTAPI_URL = "https://riciii7-tumor-detection-fastapi.hf.space"
15
+ else:
16
+ raise ValueError("Invalid environment. Choose 'local' or 'deployed'.")
17
 
18
  with open('glioma.jpg', 'rb') as f:
19
  files = {'file': ('glioma.jpg', f, 'image/jpeg')}
20
+ response = requests.post(f'{FASTAPI_URL}/inference', files=files)
21
 
22
  result = response.json()
23