Neurolingua commited on
Commit
91194cb
1 Parent(s): 44d0ab9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -13,22 +13,40 @@ if not os.path.exists(UPLOAD_FOLDER):
13
  os.makedirs(UPLOAD_FOLDER)
14
 
15
  from inference_sdk import InferenceHTTPClient
16
- def predict_disease(filepath):
 
 
 
 
 
 
 
17
  CLIENT = InferenceHTTPClient(
18
- api_url="https://classify.roboflow.com",
19
  api_key="oF1aC4b1FBCDtK8CoKx7"
20
  )
21
 
22
- result = CLIENT.infer(filepath, model_id="plant-disease-detection-iefbi/1")
23
- return result['predicted_classes'][0]
 
 
 
 
 
24
 
25
- def predict_pest(filepath):
26
  CLIENT = InferenceHTTPClient(
27
- api_url="https://detect.roboflow.com",
28
- api_key="oF1aC4b1FBCDtK8CoKx7")
 
29
 
30
- result = CLIENT.infer(filepath, model_id="pest-detection-ueoco/1")
31
- return result['predicted_classes'][0]
 
 
 
 
 
32
 
33
  # Initialize the Flask app
34
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
 
13
  os.makedirs(UPLOAD_FOLDER)
14
 
15
  from inference_sdk import InferenceHTTPClient
16
+ import base64
17
+
18
+ def encode_image_to_base64(filepath):
19
+ with open(filepath, "rb") as image_file:
20
+ encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
21
+ return encoded_string
22
+
23
+ def predict_pest(filepath):
24
  CLIENT = InferenceHTTPClient(
25
+ api_url="https://detect.roboflow.com",
26
  api_key="oF1aC4b1FBCDtK8CoKx7"
27
  )
28
 
29
+ try:
30
+ encoded_image = encode_image_to_base64(filepath)
31
+ result = CLIENT.infer(encoded_image, model_id="pest-detection-ueoco/1")
32
+ return result['predicted_classes'][0]
33
+ except Exception as e:
34
+ print(f"API call error: {e}")
35
+ return "Error during pest detection."
36
 
37
+ def predict_disease(filepath):
38
  CLIENT = InferenceHTTPClient(
39
+ api_url="https://classify.roboflow.com",
40
+ api_key="oF1aC4b1FBCDtK8CoKx7"
41
+ )
42
 
43
+ try:
44
+ encoded_image = encode_image_to_base64(filepath)
45
+ result = CLIENT.infer(encoded_image, model_id="plant-disease-detection-iefbi/1")
46
+ return result['predicted_classes'][0]
47
+ except Exception as e:
48
+ print(f"API call error: {e}")
49
+ return "Error during disease detection."
50
 
51
  # Initialize the Flask app
52
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')