location / app.py
Rahulk2197's picture
Rename app,py to app.py
49d4f7c verified
raw
history blame
664 Bytes
import streamlit as st
import requests
def get_location():
try:
response = requests.get("https://ipinfo.io/json")
data = response.json()
return {
"City": data.get("city"),
"Region": data.get("region"),
"Country": data.get("country"),
"Location (Lat, Long)": data.get("loc"),
"IP Address": data.get("ip"),
}
except Exception as e:
return {"Error": str(e)}
st.title("πŸ“ Find Your Location")
st.write("This app fetches your location using your IP address.")
if st.button("Get My Location"):
location_data = get_location()
st.json(location_data)