jonghhhh commited on
Commit
a668d50
ยท
verified ยท
1 Parent(s): 3f18c73

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
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
+