Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import json | |
| from shapely.geometry import Polygon, MultiPoint, mapping | |
| import re | |
| import geopandas as gpd | |
| from openai import OpenAI | |
| import numpy as np | |
| import os | |
| def get_coords(ase): | |
| request_url = 'https://nominatim.openstreetmap.org/search.php?q='+ase+'&polygon_geojson=1&accept-language=en&format=jsonv2' | |
| headers = { | |
| "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" | |
| } | |
| page = requests.get(request_url, headers=headers, verify=False) | |
| json_content = json.loads(page.content) | |
| all_coordinates = json_content[0]['geojson']['coordinates'][0] | |
| centroid = (float(json_content[0]['lon']), float(json_content[0]['lat'])) | |
| return all_coordinates, centroid | |
| def process_api(input_text): | |
| return {"result": get_coords(input_text)} | |
| # request_url = 'https://nominatim.openstreetmap.org/search.php?q=Glebe&polygon_geojson=1&accept-language=en&format=jsonv2' | |
| # headers = { | |
| # "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" | |
| # } | |
| # page1 = requests.get(request_url, headers=headers, verify=False) | |
| # cont = page1.content | |
| # 设置API格式为JSON | |
| gr.Interface( | |
| fn=process_api, | |
| # fn=cont, | |
| inputs="text", | |
| outputs="json", | |
| title="Backend API", | |
| allow_flagging="never" | |
| ).launch() |