Spaces:
Sleeping
Sleeping
Neurolingua
commited on
Commit
•
e615e06
1
Parent(s):
eea9714
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from flask import Flask, request
|
2 |
from twilio.twiml.messaging_response import MessagingResponse
|
3 |
from twilio.rest import Client
|
@@ -27,6 +28,8 @@ def classify_disease(image):
|
|
27 |
# Implement disease classification model here
|
28 |
return "Detected Disease: [Disease Name]"
|
29 |
|
|
|
|
|
30 |
@app.route('/whatsapp', methods=['POST'])
|
31 |
def whatsapp_webhook():
|
32 |
incoming_msg = request.values.get('Body', '').lower()
|
@@ -41,15 +44,18 @@ def whatsapp_webhook():
|
|
41 |
|
42 |
if content_type.startswith('image/'):
|
43 |
# Download and process the image
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
51 |
else:
|
52 |
-
response_text = "
|
53 |
else:
|
54 |
response_text = "The attached file is not an image. Please send an image for classification."
|
55 |
elif 'bookkeeping' in incoming_msg:
|
@@ -58,7 +64,7 @@ def whatsapp_webhook():
|
|
58 |
response_text = get_agricultural_insights(incoming_msg)
|
59 |
|
60 |
send_message(sender, response_text)
|
61 |
-
return '', 204
|
62 |
|
63 |
def get_agricultural_insights(query):
|
64 |
# Implement your agricultural insights logic here
|
|
|
1 |
+
import requests
|
2 |
from flask import Flask, request
|
3 |
from twilio.twiml.messaging_response import MessagingResponse
|
4 |
from twilio.rest import Client
|
|
|
28 |
# Implement disease classification model here
|
29 |
return "Detected Disease: [Disease Name]"
|
30 |
|
31 |
+
|
32 |
+
|
33 |
@app.route('/whatsapp', methods=['POST'])
|
34 |
def whatsapp_webhook():
|
35 |
incoming_msg = request.values.get('Body', '').lower()
|
|
|
44 |
|
45 |
if content_type.startswith('image/'):
|
46 |
# Download and process the image
|
47 |
+
response = requests.get(media_url)
|
48 |
+
if response.status_code == 200:
|
49 |
+
image = Image.open(io.BytesIO(response.content))
|
50 |
+
|
51 |
+
if 'pest' in incoming_msg:
|
52 |
+
response_text = classify_pest(image)
|
53 |
+
elif 'disease' in incoming_msg:
|
54 |
+
response_text = classify_disease(image)
|
55 |
+
else:
|
56 |
+
response_text = "Please specify if you want to detect a pest or a disease."
|
57 |
else:
|
58 |
+
response_text = "Failed to download the image. Please try again."
|
59 |
else:
|
60 |
response_text = "The attached file is not an image. Please send an image for classification."
|
61 |
elif 'bookkeeping' in incoming_msg:
|
|
|
64 |
response_text = get_agricultural_insights(incoming_msg)
|
65 |
|
66 |
send_message(sender, response_text)
|
67 |
+
return '', 204
|
68 |
|
69 |
def get_agricultural_insights(query):
|
70 |
# Implement your agricultural insights logic here
|