Spaces:
Sleeping
Sleeping
Rename app,py to app.py
Browse files
app,py
DELETED
|
File without changes
|
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
def get_location():
|
| 5 |
+
try:
|
| 6 |
+
response = requests.get("https://ipinfo.io/json")
|
| 7 |
+
data = response.json()
|
| 8 |
+
return {
|
| 9 |
+
"City": data.get("city"),
|
| 10 |
+
"Region": data.get("region"),
|
| 11 |
+
"Country": data.get("country"),
|
| 12 |
+
"Location (Lat, Long)": data.get("loc"),
|
| 13 |
+
"IP Address": data.get("ip"),
|
| 14 |
+
}
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return {"Error": str(e)}
|
| 17 |
+
|
| 18 |
+
st.title("📍 Find Your Location")
|
| 19 |
+
|
| 20 |
+
st.write("This app fetches your location using your IP address.")
|
| 21 |
+
|
| 22 |
+
if st.button("Get My Location"):
|
| 23 |
+
location_data = get_location()
|
| 24 |
+
st.json(location_data)
|