Neurolingua commited on
Commit
082246f
1 Parent(s): 7241f1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -5
app.py CHANGED
@@ -11,6 +11,23 @@ app = Flask(__name__)
11
  UPLOAD_FOLDER = 'uploads'
12
  if not os.path.exists(UPLOAD_FOLDER):
13
  os.makedirs(UPLOAD_FOLDER)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  # Initialize the Flask app
16
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
@@ -51,15 +68,15 @@ def whatsapp_webhook():
51
 
52
 
53
 
54
- if 'pest' in incoming_msg:
55
- response_text = classify_pest(filepath)
56
- elif 'disease' in incoming_msg:
57
- response_text = classify_disease(filepath)
58
  else:
59
  response_text = "Please specify if you want to detect a pest or a disease."
60
  except Exception as e:
61
  print(f"Error processing image: {e}")
62
- response_text = filepath
63
  else:
64
  response_text = "The attached file is not an image. Please send an image for classification."
65
  elif 'bookkeeping' in incoming_msg:
 
11
  UPLOAD_FOLDER = 'uploads'
12
  if not os.path.exists(UPLOAD_FOLDER):
13
  os.makedirs(UPLOAD_FOLDER)
14
+ from inference_sdk import InferenceHTTPClient
15
+ def predict_disease(filepath):
16
+ CLIENT = InferenceHTTPClient(
17
+ api_url="https://classify.roboflow.com",
18
+ api_key="oF1aC4b1FBCDtK8CoKx7"
19
+ )
20
+
21
+ result = CLIENT.infer(filepath, model_id="plant-disease-detection-iefbi/1")
22
+ return result['predicted_classes'][0]
23
+
24
+ def predict_pest(filepath):
25
+ CLIENT = InferenceHTTPClient(
26
+ api_url="https://detect.roboflow.com",
27
+ api_key="oF1aC4b1FBCDtK8CoKx7")
28
+
29
+ result = CLIENT.infer(filepath, model_id="pest-detection-ueoco/1")
30
+ return result['predicted_classes'][0]
31
 
32
  # Initialize the Flask app
33
  account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
 
68
 
69
 
70
 
71
+ if ('pest' in incoming_msg) or ('Pest' in incoming_msg):
72
+ response_text = predict_pest(filepath)
73
+ elif ('disease' in incoming_msg) or ('Disease' in incoming_msg):
74
+ response_text = predict_disease(filepath)
75
  else:
76
  response_text = "Please specify if you want to detect a pest or a disease."
77
  except Exception as e:
78
  print(f"Error processing image: {e}")
79
+ response_text = 'Invalid image'
80
  else:
81
  response_text = "The attached file is not an image. Please send an image for classification."
82
  elif 'bookkeeping' in incoming_msg: