Neurolingua
commited on
Commit
•
91194cb
1
Parent(s):
44d0ab9
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
CLIENT = InferenceHTTPClient(
|
18 |
-
api_url="https://
|
19 |
api_key="oF1aC4b1FBCDtK8CoKx7"
|
20 |
)
|
21 |
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
def
|
26 |
CLIENT = InferenceHTTPClient(
|
27 |
-
|
28 |
-
|
|
|
29 |
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
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')
|