Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,25 +9,32 @@ import numpy as np
|
|
| 9 |
import os
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def process_api(input_text):
|
| 14 |
-
|
| 15 |
|
| 16 |
-
# return {
|
| 17 |
-
# "status": "success",
|
| 18 |
-
# # "result": f"Processed: {input_text.upper()}",
|
| 19 |
-
# "result": f"Processed: {nlp(input_text).to_json()}",
|
| 20 |
-
# "timestamp": time.time()
|
| 21 |
-
# }
|
| 22 |
|
| 23 |
-
return input_text.upper()
|
| 24 |
|
| 25 |
-
request_url = 'https://nominatim.openstreetmap.org/search.php?q=Glebe&polygon_geojson=1&accept-language=en&format=jsonv2'
|
| 26 |
-
headers = {
|
| 27 |
-
|
| 28 |
-
}
|
| 29 |
-
page1 = requests.get(request_url, headers=headers, verify=False)
|
| 30 |
-
cont = page1.content
|
| 31 |
|
| 32 |
# 设置API格式为JSON
|
| 33 |
gr.Interface(
|
|
@@ -37,7 +44,4 @@ gr.Interface(
|
|
| 37 |
outputs="json",
|
| 38 |
title="Backend API",
|
| 39 |
allow_flagging="never"
|
| 40 |
-
).launch(
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 9 |
import os
|
| 10 |
|
| 11 |
|
| 12 |
+
def get_coords(ase):
|
| 13 |
+
request_url = 'https://nominatim.openstreetmap.org/search.php?q='+ase+'&polygon_geojson=1&accept-language=en&format=jsonv2'
|
| 14 |
+
headers = {
|
| 15 |
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15"
|
| 16 |
+
}
|
| 17 |
+
page = requests.get(request_url, headers=headers, verify=False)
|
| 18 |
+
json_content = json.loads(page.content)
|
| 19 |
+
|
| 20 |
+
all_coordinates = json_content[0]['geojson']['coordinates'][0]
|
| 21 |
+
centroid = (float(json_content[0]['lon']), float(json_content[0]['lat']))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
return all_coordinates, centroid
|
| 26 |
|
| 27 |
def process_api(input_text):
|
| 28 |
+
return {"result": get_coords(input_text)}
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
|
|
|
| 31 |
|
| 32 |
+
# request_url = 'https://nominatim.openstreetmap.org/search.php?q=Glebe&polygon_geojson=1&accept-language=en&format=jsonv2'
|
| 33 |
+
# headers = {
|
| 34 |
+
# "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15"
|
| 35 |
+
# }
|
| 36 |
+
# page1 = requests.get(request_url, headers=headers, verify=False)
|
| 37 |
+
# cont = page1.content
|
| 38 |
|
| 39 |
# 设置API格式为JSON
|
| 40 |
gr.Interface(
|
|
|
|
| 44 |
outputs="json",
|
| 45 |
title="Backend API",
|
| 46 |
allow_flagging="never"
|
| 47 |
+
).launch()
|
|
|
|
|
|
|
|
|