Spaces:
Sleeping
Sleeping
Neurolingua
commited on
Commit
•
d258a15
1
Parent(s):
4248e55
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ from PIL import Image
|
|
7 |
import io
|
8 |
import uuid
|
9 |
import shutil
|
|
|
10 |
app = Flask(__name__)
|
11 |
UPLOAD_FOLDER = '/code/uploads'
|
12 |
if not os.path.exists(UPLOAD_FOLDER):
|
@@ -17,33 +18,8 @@ import base64
|
|
17 |
|
18 |
|
19 |
|
20 |
-
def predict_pest(filepath):
|
21 |
-
CLIENT = InferenceHTTPClient(
|
22 |
-
api_url="https://detect.roboflow.com",
|
23 |
-
api_key="oF1aC4b1FBCDtK8CoKx7"
|
24 |
-
)
|
25 |
-
|
26 |
-
try:
|
27 |
-
encoded_image = encode_image_to_base64(filepath)
|
28 |
-
result = CLIENT.infer(encoded_image, model_id="pest-detection-ueoco/1")
|
29 |
-
return result['predicted_classes'][0]
|
30 |
-
except Exception as e:
|
31 |
-
print(f"API call error: {e}")
|
32 |
-
return e
|
33 |
|
34 |
-
def predict_disease(filepath):
|
35 |
-
CLIENT = InferenceHTTPClient(
|
36 |
-
api_url="https://classify.roboflow.com",
|
37 |
-
api_key="oF1aC4b1FBCDtK8CoKx7"
|
38 |
-
)
|
39 |
|
40 |
-
try:
|
41 |
-
encoded_image = encode_image_to_base64(filepath)
|
42 |
-
result = CLIENT.infer(encoded_image, model_id="plant-disease-detection-iefbi/1")
|
43 |
-
return result['predicted_classes'][0]
|
44 |
-
except Exception as e:
|
45 |
-
print(f"API call error: {e}")
|
46 |
-
return e
|
47 |
|
48 |
# Initialize the Flask app
|
49 |
account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
|
@@ -76,8 +52,7 @@ def whatsapp_webhook():
|
|
76 |
r.raise_for_status()'''
|
77 |
response_text=media_url
|
78 |
|
79 |
-
|
80 |
-
filename = f"{uuid.uuid4()}.jpg"
|
81 |
filepath = os.path.join(UPLOAD_FOLDER, filename)
|
82 |
|
83 |
if 1==1:
|
|
|
7 |
import io
|
8 |
import uuid
|
9 |
import shutil
|
10 |
+
from other_function import predict_pest,predict_disease,convert_img
|
11 |
app = Flask(__name__)
|
12 |
UPLOAD_FOLDER = '/code/uploads'
|
13 |
if not os.path.exists(UPLOAD_FOLDER):
|
|
|
18 |
|
19 |
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Initialize the Flask app
|
25 |
account_sid = os.environ.get('TWILIO_ACCOUNT_SID')
|
|
|
52 |
r.raise_for_status()'''
|
53 |
response_text=media_url
|
54 |
|
55 |
+
|
|
|
56 |
filepath = os.path.join(UPLOAD_FOLDER, filename)
|
57 |
|
58 |
if 1==1:
|