Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit.components.v1 import html
|
| 3 |
+
|
| 4 |
+
# JavaScript๋ก Geolocation API๋ฅผ ์ฌ์ฉํ์ฌ ์์น ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
|
| 5 |
+
geo_loc_script = """
|
| 6 |
+
<script>
|
| 7 |
+
function getLocation() {
|
| 8 |
+
if (navigator.geolocation) {
|
| 9 |
+
navigator.geolocation.getCurrentPosition(showPosition);
|
| 10 |
+
} else {
|
| 11 |
+
document.getElementById("location").innerHTML = "์ด ๋ธ๋ผ์ฐ์ ์์๋ ์์น ์ ๋ณด๋ฅผ ์ง์ํ์ง ์์ต๋๋ค.";
|
| 12 |
+
}
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function showPosition(position) {
|
| 16 |
+
document.getElementById("location").value = position.coords.latitude + "," + position.coords.longitude;
|
| 17 |
+
document.getElementById("location_form").submit();
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
getLocation();
|
| 21 |
+
</script>
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
# Streamlit ์ฑ์ ๊ธฐ๋ณธ UI
|
| 25 |
+
st.title('์ถ์ ์ ๊ฒ')
|
| 26 |
+
|
| 27 |
+
st.write('์๋ ์ ๋ณด๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.')
|
| 28 |
+
|
| 29 |
+
# HTML form์ ์ฌ์ฉํ์ฌ ์์น ์ ๋ณด์ ํจ๊ป ๋ฐ์ดํฐ๋ฅผ ์ ์ก
|
| 30 |
+
html_form = """
|
| 31 |
+
<form action="" method="get" id="location_form">
|
| 32 |
+
<input type="text" name="location" id="location" hidden>
|
| 33 |
+
<label for="name">์ด๋ฆ:</label><br>
|
| 34 |
+
<input type="text" id="name" name="name"><br>
|
| 35 |
+
<label for="email">์ด๋ฉ์ผ:</label><br>
|
| 36 |
+
<input type="email" id="email" name="email"><br>
|
| 37 |
+
<input type="submit" value="์ ์ถ">
|
| 38 |
+
</form>
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
# Streamlit์์ HTML๊ณผ JS ์ฝ์
|
| 42 |
+
html(html_form + geo_loc_script)
|
| 43 |
+
|
| 44 |
+
# ์ฌ์ฉ์๊ฐ ํผ์ ์ ์ถํ ํ ์ฒ๋ฆฌ
|
| 45 |
+
if 'location' in st.experimental_get_query_params():
|
| 46 |
+
location = st.experimental_get_query_params()['location'][0]
|
| 47 |
+
st.write(f"๋น์ ์ ์์น: {location}")
|
| 48 |
+
st.write("์ถ์ ์ ๊ฒ์ ์ํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค!")
|
| 49 |
+
else:
|
| 50 |
+
st.write("์๋ต์ ๊ธฐ๋ค๋ฆฌ๊ณ ์์ต๋๋ค...")
|
| 51 |
+
|