MLDeveloper commited on
Commit
47de9ba
·
verified ·
1 Parent(s): 3a2e792

Update firebase_credentials.json

Browse files
Files changed (1) hide show
  1. firebase_credentials.json +105 -13
firebase_credentials.json CHANGED
@@ -1,13 +1,105 @@
1
- {
2
- "type": "service_account",
3
- "project_id": "binsight-beda0",
4
- "private_key_id": "86c2e13649ff195cab006525a8ce7bef4cc4f058",
5
- "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDN4c+3mtX7swWt\nfqr1LHDaseFRS3FKWHt56r4uYOvSGsubpqesNLE9PVAtHcAJx+ZUiSN2vGEu1T6v\n+0zRtkUUVqlnKEt5xmDtylWJJfkC0y0eu3wF9xN5YhEbfwBH+q9mkJx9eFCVMcQP\nVf2r0NpOkaH0n1Bw+5v3SWvptSnf5dbkKtYq8VaFZ1lKjTGpW86kGDBik7kEwO0F\n7ccImILj5RjikZz9b5+g+L4m9JzXVzdug8SAKwGEWB+lcNNUQzw+MZUTQmrrvtzl\nbAdL3fQS094Fj4lEvSccxw1yILwh9XNEir26ZaV4KLLB3a2yzbi8Vug6Zss5VM1j\n99kMalcTAgMBAAECggEACXy6Ya+U5MBfJpuLrTibCrjftStQ0Sg6qGeU0/ZLZ6cs\ncsO/PkQ/Vp8YrruMOecoSgT3yWTs5YeWF+3woElR7ZoAvGwy7i2iEdMdFfDWBLdO\ngPgKwwubriBCwY2cqbR3mLZZP77nl7hvXHWN9vjs1moHmIou3sX5be/INUDP6S1N\nBgdtvYb7eZY8bABuZ2xGZcO8Qai9d/UrytcoblNmDGz5bB5JQBS2Q0JVzvxTpK49\nypbdPGyvpBxRguKgK5aBiAcftfjnU0TfKthOjGMkWwVrwRz8YsotN6eqQCeHB4Qx\nDDkQzluqWI3VAgenfwD7CjbXMYI1/AQhW4Psl+oB4QKBgQDxqAoI1GqSz+WxBBzZ\nQQ+8sNKuZQEgbWks/VbGds0Sejx0HaaUA8WIjBg6OEOQACUcH8EdZUWGcKfQr6w/\nRFNoJFgXtiiKjZBrFHpAGC9jzGDCRCmTrTMpTIc6r2+tF2nOJm98ue2OGN+Wcj0e\n0dHtRnbbgHdqDn/fVwhIrvFqrQKBgQDaGi65QGzo9XI6kJ+ckssRcDVmaEvNxDc4\nZ0e4j2+ExaFdz3Q+WR3auqIJE3gzv6PTWpKE60Nl/KKbqHKaUSap11Xzm3A64r4B\nRJzkTaWvSVnIIPQ+LCy+7gNOiZOg7G8ddA1Dw2Vh8xs0Ds7hufMlCz81uXoac42b\nr5UFsrLAvwKBgEl2bw5+HKPi5Y2plWeKOtF+4502gWAtQqL1pPKSXQc397bI6MHo\nX52CET9pqUhWcvGYyak5Byi2iJ2NOgzFpaFsIweaTbrJDFUxFXT0pTtufx+vfwAw\nz/PHGvkBKi7xhi2wS4YcM5ZWA2qF8gSzfmDmYe2aoTKxk7f+ijsmS6fFAoGAUr0o\nCIMWTfH/GZSP2HgfrUfiGi1qxG6xfCZCIRPY/Id0xf/TW2u3VakDm2nVadxDrARq\nHR6a/O+wSFjI0R4ECt5z7uyC0PP/nL+IvVtvhWXQN4m43nUnrG7itkKezKelJ4lF\nFvXjWhs9sKwFc8B1KxJvMlRgq/Q2Pl+Hqxe1lEUCgYEAw1edm/iMOK4M+Uu1cMjR\nY1Ebv0krcgq7c1xww0uwbNzbaULNQ/WA0VjCRr2vQIvwvl/vvzFS22y05YYRpIkd\nRrE//iuTHvT9dWQ0LwdwmQGLw5D+2aUra4r4oxFJSee227GReVZzVJLMdBzN6Nlf\nc90EgNm0/XVwiU8ffvVNKvI=\n-----END PRIVATE KEY-----\n",
6
- "client_email": "firebase-adminsdk-fbsvc@binsight-beda0.iam.gserviceaccount.com",
7
- "client_id": "117807845711034166542",
8
- "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
- "token_uri": "https://oauth2.googleapis.com/token",
10
- "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
- "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-fbsvc%40binsight-beda0.iam.gserviceaccount.com",
12
- "universe_domain": "googleapis.com"
13
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import firebase_admin
4
+ from firebase_admin import credentials, db
5
+ from PIL import Image
6
+ import numpy as np
7
+ from geopy.geocoders import Nominatim
8
+ from tensorflow.keras.applications import MobileNetV2
9
+ from tensorflow.keras.applications.mobilenet_v2 import decode_predictions, preprocess_input
10
+
11
+ # Initialize Firebase (Load credentials from JSON file)
12
+ if not firebase_admin._apps:
13
+ try:
14
+ cred = credentials.Certificate("firebase_credentials.json")
15
+ firebase_admin.initialize_app(cred, {
16
+ 'databaseURL': 'https://binsight-beda0-default-rtdb.asia-southeast1.firebasedatabase.app/'
17
+ })
18
+ print("✅ Firebase initialized successfully!")
19
+ except Exception as e:
20
+ st.error(f"❌ Firebase initialization failed: {e}")
21
+
22
+ # Load MobileNetV2 pre-trained model
23
+ mobilenet_model = MobileNetV2(weights="imagenet")
24
+
25
+ # Function to classify image using MobileNetV2
26
+ def classify_image_with_mobilenet(image):
27
+ try:
28
+ img = image.resize((224, 224))
29
+ img_array = np.array(img)
30
+ img_array = np.expand_dims(img_array, axis=0)
31
+ img_array = preprocess_input(img_array)
32
+ predictions = mobilenet_model.predict(img_array)
33
+ labels = decode_predictions(predictions, top=5)[0]
34
+ return {label[1]: float(label[2]) for label in labels}
35
+ except Exception as e:
36
+ st.error(f"Error during image classification: {e}")
37
+ return {}
38
+
39
+ # Function to get user location
40
+ def get_user_location():
41
+ st.write("Fetching location, please allow location access in your browser.")
42
+ geolocator = Nominatim(user_agent="binsight")
43
+ try:
44
+ ip_info = requests.get("https://ipinfo.io/json").json()
45
+ loc = ip_info.get("loc", "").split(",")
46
+ latitude, longitude = loc[0], loc[1] if len(loc) == 2 else (None, None)
47
+ if latitude and longitude:
48
+ address = geolocator.reverse(f"{latitude}, {longitude}").address
49
+ return latitude, longitude, address
50
+ except Exception as e:
51
+ st.error(f"Error retrieving location: {e}")
52
+ return None, None, None
53
+
54
+ # User Login
55
+ st.sidebar.header("User Login")
56
+ user_email = st.sidebar.text_input("Enter your email")
57
+ login_button = st.sidebar.button("Login")
58
+
59
+ if login_button:
60
+ if user_email:
61
+ st.session_state["user_email"] = user_email
62
+ st.sidebar.success(f"Logged in as {user_email}")
63
+
64
+ if "user_email" not in st.session_state:
65
+ st.warning("Please log in first.")
66
+ st.stop()
67
+
68
+ # Get user location
69
+ latitude, longitude, address = get_user_location()
70
+ if latitude and longitude:
71
+ st.success(f"Location detected: {address}")
72
+ else:
73
+ st.warning("Unable to fetch location, please enable location access.")
74
+ st.stop()
75
+
76
+ # Streamlit App
77
+ st.title("BinSight: Upload Dustbin Image")
78
+
79
+ uploaded_file = st.file_uploader("Upload an image of the dustbin", type=["jpg", "jpeg", "png"])
80
+ submit_button = st.button("Analyze and Upload")
81
+
82
+ if submit_button and uploaded_file:
83
+ image = Image.open(uploaded_file)
84
+ st.image(image, caption="Uploaded Image", use_container_width=True)
85
+
86
+ classification_results = classify_image_with_mobilenet(image)
87
+
88
+ if classification_results:
89
+ db_ref = db.reference("dustbins")
90
+ dustbin_data = {
91
+ "user_email": st.session_state["user_email"],
92
+ "latitude": latitude,
93
+ "longitude": longitude,
94
+ "address": address,
95
+ "classification": classification_results,
96
+ "allocated_truck": None,
97
+ "status": "Pending"
98
+ }
99
+ db_ref.push(dustbin_data)
100
+ st.success("Dustbin data uploaded successfully!")
101
+ st.write(f"**Location:** {address}")
102
+ st.write(f"**Latitude:** {latitude}, **Longitude:** {longitude}")
103
+ else:
104
+ st.error("Missing classification details. Cannot upload.")
105
+