Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,13 +14,26 @@ FROM_PHONE = '+13613093564'
|
|
14 |
TO_PHONE = '+919080522395'
|
15 |
|
16 |
# Firebase Configuration
|
17 |
-
FIREBASE_CREDENTIALS_PATH = r"
|
18 |
THINGSPEAK_API_KEY = "P54KXM40TA3CB6W4"
|
19 |
CHANNEL_ID = "2784385"
|
20 |
|
21 |
# Global variable to track the last entry ID
|
22 |
last_entry_id = None
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
# Initialize Firebase
|
25 |
cred = credentials.Certificate(FIREBASE_CREDENTIALS_PATH)
|
26 |
firebase_admin.initialize_app(cred)
|
@@ -44,12 +57,18 @@ def send_msg(doc_id, field1):
|
|
44 |
|
45 |
# Check if the message status is 0
|
46 |
if msg_status == 0:
|
|
|
47 |
client = Client(ACCOUNT_SID, AUTH_TOKEN)
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
49 |
# Send the message
|
50 |
message = client.messages.create(
|
51 |
from_=FROM_PHONE,
|
52 |
-
body=f"""E.coli Level: {
|
53 |
to=TO_PHONE
|
54 |
)
|
55 |
|
|
|
14 |
TO_PHONE = '+919080522395'
|
15 |
|
16 |
# Firebase Configuration
|
17 |
+
FIREBASE_CREDENTIALS_PATH = r"snippetscript-37175-firebase-adminsdk-cf1z8-7d509b09fd.json"
|
18 |
THINGSPEAK_API_KEY = "P54KXM40TA3CB6W4"
|
19 |
CHANNEL_ID = "2784385"
|
20 |
|
21 |
# Global variable to track the last entry ID
|
22 |
last_entry_id = None
|
23 |
+
with open('model.pkl', 'rb') as f:
|
24 |
+
loaded_model = pickle.load(f)
|
25 |
+
def predict_conc(pdiff):
|
26 |
+
try:
|
27 |
+
if pdiff > 3.19:
|
28 |
+
return 0
|
29 |
+
pdiff_value = pdiff # Input for "Average Potential Difference"
|
30 |
+
new_data = np.array([[pdiff_value]])
|
31 |
+
prediction = loaded_model.predict(new_data)
|
32 |
+
concentration = 10**prediction[0] # Reverse log transformation
|
33 |
+
return f"{concentration:.4f}"
|
34 |
+
except Exception as e:
|
35 |
+
print(f"Error in predict_conc: {e}")
|
36 |
+
return None
|
37 |
# Initialize Firebase
|
38 |
cred = credentials.Certificate(FIREBASE_CREDENTIALS_PATH)
|
39 |
firebase_admin.initialize_app(cred)
|
|
|
57 |
|
58 |
# Check if the message status is 0
|
59 |
if msg_status == 0:
|
60 |
+
concen=predict_conc(int(field1))
|
61 |
client = Client(ACCOUNT_SID, AUTH_TOKEN)
|
62 |
+
if concen!=0:
|
63 |
+
sugges="You may heat your water to eradicate the bacteria."
|
64 |
+
else:
|
65 |
+
sugges="Your water is safe.It can be used for drinking purpose!."
|
66 |
+
|
67 |
+
|
68 |
# Send the message
|
69 |
message = client.messages.create(
|
70 |
from_=FROM_PHONE,
|
71 |
+
body=f"""E.coli Level: {concen} CFU/mL\nStatus: Safe\nSuggestions:\n{sugges}\n--Ministry of Jal Shakthi.""",
|
72 |
to=TO_PHONE
|
73 |
)
|
74 |
|