Spaces:
Sleeping
Sleeping
Neurolingua
commited on
Commit
•
36ec663
1
Parent(s):
d258a15
Update app.py
Browse files
app.py
CHANGED
@@ -12,13 +12,6 @@ app = Flask(__name__)
|
|
12 |
UPLOAD_FOLDER = '/code/uploads'
|
13 |
if not os.path.exists(UPLOAD_FOLDER):
|
14 |
os.makedirs(UPLOAD_FOLDER)
|
15 |
-
|
16 |
-
from inference_sdk import InferenceHTTPClient
|
17 |
-
import base64
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
|
23 |
|
24 |
# Initialize the Flask app
|
@@ -28,13 +21,6 @@ client = Client(account_sid, auth_token)
|
|
28 |
# WhatsApp number to send messages from (your Twilio number)
|
29 |
from_whatsapp_number = 'whatsapp:+14155238886'
|
30 |
|
31 |
-
def classify_pest(image_path):
|
32 |
-
# Implement pest classification model here
|
33 |
-
return f"Detected Pest: [Pest Name] for image at {image_path}"
|
34 |
-
|
35 |
-
def classify_disease(image_path):
|
36 |
-
# Implement disease classification model here
|
37 |
-
return f"Detected Disease: [Disease Name] for image at {image_path}"
|
38 |
@app.route('/whatsapp', methods=['POST'])
|
39 |
def whatsapp_webhook():
|
40 |
incoming_msg = request.values.get('Body', '').lower()
|
@@ -48,27 +34,18 @@ def whatsapp_webhook():
|
|
48 |
content_type = request.values.get('MediaContentType0')
|
49 |
|
50 |
if content_type.startswith('image/'):
|
51 |
-
'''r = requests.get(media_url)
|
52 |
-
r.raise_for_status()'''
|
53 |
-
response_text=media_url
|
54 |
|
55 |
|
56 |
-
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
if
|
64 |
-
response_text = "The image file is empty. Please send a valid image."
|
65 |
-
else:
|
66 |
-
if 'pest' in incoming_msg:
|
67 |
-
response_text = predict_pest(filepath)
|
68 |
-
elif 'disease' in incoming_msg:
|
69 |
-
response_text = predict_disease(filepath)
|
70 |
-
else:
|
71 |
-
response_text = "Please specify if you want to detect a pest or a disease."'''
|
72 |
|
73 |
else:
|
74 |
response_text = "The attached file is not an image. Please send an image for classification."
|
|
|
12 |
UPLOAD_FOLDER = '/code/uploads'
|
13 |
if not os.path.exists(UPLOAD_FOLDER):
|
14 |
os.makedirs(UPLOAD_FOLDER)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
|
17 |
# Initialize the Flask app
|
|
|
21 |
# WhatsApp number to send messages from (your Twilio number)
|
22 |
from_whatsapp_number = 'whatsapp:+14155238886'
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
@app.route('/whatsapp', methods=['POST'])
|
25 |
def whatsapp_webhook():
|
26 |
incoming_msg = request.values.get('Body', '').lower()
|
|
|
34 |
content_type = request.values.get('MediaContentType0')
|
35 |
|
36 |
if content_type.startswith('image/'):
|
|
|
|
|
|
|
37 |
|
38 |
|
39 |
+
|
40 |
+
|
41 |
+
filepath = convert_img(media_url, account_sid, auth_token)
|
42 |
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
response_text = predict_disease(filepath)
|
47 |
+
else:
|
48 |
+
response_text = "Please specify if you want to detect a pest or a disease."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
else:
|
51 |
response_text = "The attached file is not an image. Please send an image for classification."
|