Muhanuri commited on
Commit
55f5218
Β·
verified Β·
1 Parent(s): 59f61e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -12
app.py CHANGED
@@ -1,20 +1,36 @@
1
  import requests
 
 
2
 
3
  # Google SERP API 킀와 검색어 μ„€μ •
4
  api_key = "e312d83a4f8dc1ea07419ea7d234d3aacd0abe11f781504d554f06c2ac1db0ab"
5
  query = "Seoul"
6
 
7
- # Google SERP API URL ꡬ성
8
- url = f"https://serpapi.com/search.json?q={query}&location=Seoul,Seoul,South Korea&hl=en&gl=us&google_domain=google.com&api_key={api_key}"
 
9
 
10
- # API μš”μ²­
11
- response = requests.get(url)
12
 
13
- # 응닡 확인
14
- if response.status_code == 200:
15
- # μ‘λ‹΅μ—μ„œ μœ„μΉ˜ 정보 μΆ”μΆœ
16
- data = response.json()
17
- # μ˜ˆμ œμ—μ„œλŠ” κ°„λ‹¨νžˆ μ‘λ‹΅μ˜ 일뢀λ₯Ό 좜λ ₯ν•©λ‹ˆλ‹€. μ‹€μ œλ‘œλŠ” ν•„μš”ν•œ 정보λ₯Ό μΆ”μΆœν•˜μ—¬ μ‚¬μš©ν•©λ‹ˆλ‹€.
18
- print(data)
19
- else:
20
- print("Error:", response.status_code)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import requests
2
+ import folium
3
+ import gradio as gr
4
 
5
  # Google SERP API 킀와 검색어 μ„€μ •
6
  api_key = "e312d83a4f8dc1ea07419ea7d234d3aacd0abe11f781504d554f06c2ac1db0ab"
7
  query = "Seoul"
8
 
9
+ def search_and_display_map():
10
+ # Google SERP API URL ꡬ성
11
+ url = f"https://serpapi.com/search.json?q={query}&location=Seoul,Seoul,South Korea&hl=en&gl=us&google_domain=google.com&api_key={api_key}"
12
 
13
+ # API μš”μ²­
14
+ response = requests.get(url)
15
 
16
+ # 응닡 확인 및 지도 생성
17
+ if response.status_code == 200:
18
+ data = response.json()
19
+ # μ—¬κΈ°μ„œλŠ” μ˜ˆμ‹œλ‘œ μ„œμšΈμ˜ μœ„λ„μ™€ 경도λ₯Ό μ‚¬μš©ν•©λ‹ˆλ‹€. μ‹€μ œ μ‘λ‹΅μ—μ„œ ν•„μš”ν•œ μœ„μΉ˜ 정보λ₯Ό μΆ”μΆœν•˜μ—¬ μ‚¬μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€.
20
+ latitude = 37.5665
21
+ longitude = 126.9780
22
+
23
+ # Folium을 μ‚¬μš©ν•˜μ—¬ 지도 생성
24
+ map = folium.Map(location=[latitude, longitude], zoom_start=13)
25
+
26
+ # 지도λ₯Ό HTML 파일둜 μ €μž₯
27
+ map.save('map.html')
28
+ return 'map.html'
29
+ else:
30
+ return "Error: API μš”μ²­μ— μ‹€νŒ¨ν–ˆμŠ΅λ‹ˆλ‹€."
31
+
32
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
33
+ iface = gr.Interface(fn=search_and_display_map, inputs=[], outputs="html")
34
+
35
+ # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
36
+ iface.launch()