Spaces:
Sleeping
Sleeping
File size: 2,167 Bytes
c9da2ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
import streamlit as st
# Fetch the credential JSON file from your Firebase project settings
# and upload it to Google Colab, then provide the path here
cred = credentials.Certificate("/cid1234-firebase-adminsdk-o0jz2-ddc0afe71d.json")
# Initialize the app with the credentials and your database URL
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://cid1234-default-rtdb.firebaseio.com/'
})
# Reference to your Firebase database
ref = db.reference('/')
# Listen for changes in the database in real-time
def on_change(event):
st.write('Data changed:', event.path, event.data)
ref.listen(on_change)
import requests
def get_coordinates(location):
"""
Get latitude and longitude of a location using OpenStreetMap Nominatim API
"""
# URL for OpenStreetMap Nominatim API
url = f'https://nominatim.openstreetmap.org/search?format=json&q={location}'
# Send request to the API
response = requests.get(url)
# Parse JSON response
data = response.json()
# Check if response is not empty
if data:
# Extract latitude and longitude from the first result
lat = float(data[0]['lat'])
lon = float(data[0]['lon'])
return lat, lon
else:
st.write("No results found for the location.")
return None
# Example usage
location = input("Enter Location: ")
latitude, longitude = get_coordinates(location)
if latitude and longitude:
st.write(f"Latitude: {latitude}, Longitude: {longitude}")
else:
st.write("Failed to retrieve coordinates for the location.")
crimes = pd.DataFrame(columns=['Name', 'Lat', 'Lon', 'Intensity'])
query = ""
while(query != 'N'):
location = input("Enter Location: ")
crime = input("Enter Crime: ")
intensity = int(input("Enter Intensity: "))
latitude, longitude = get_coordinates(location)
data = [{'Name': crime, 'Lat': latitude, 'Lon': longitude, 'Intensity': intensity}]
query = input("Enter Y to continue and N to stop: ")
crimes = pd.concat([crimes, pd.DataFrame(data)], ignore_index=True)
st.write(crimes)
|