Spaces:
Sleeping
Sleeping
Shunfeng Zheng commited on
Update pages/2_Tagger.py
Browse files17 unmodified lines1819202121222324277 unmodified lines30230330430530630730829 unmodified lines3383393403413423433443453463473483493503513523533543553563573583593603613623633647 unmodified lines37237337435337537637737835735835937938038138238338436138538638736338838939039117 unmodified linesfrom streamlit.components.v1 import htmlfrom spacy.tokens import Span, Docfrom utils import llm_coding
import os
def nav_page(page_name, timeout_secs=3):277 unmodified lines def draw_location(geojson): #gj = json.load(geojson) geojson = geojson['data'][0] centroid = geojson['features'][0]['properties']['centroid'] centroid = (centroid[0],centroid[1]) my_map = folium.Map(location=[centroid[1], centroid[0]],29 unmodified lines end = start + len(text) return Span(doc, doc.char_span(start, end, label=label).start, doc.char_span(start, end, label=label).end, label=label)
API_TOKEN = os.getenv('API_TOKEN2')
BACKEND_URL = "https://dsbb0707-dockerb21.hf.space/api/predict/"
import requestsdef call_backend(input_text): try: headers = { "Authorization": f"Bearer {API_TOKEN}" } response = requests.post( BACKEND_URL, headers=headers, json={"data": [input_text]}, timeout=10 ) if response.status_code == 200: return response.json() # ✅ 保留原始 JSON 对象 (dict) return {"error": f"❌ Backend Error (HTTP {response.status_code})"} except Exception as e: return {"error": f"⚠️ Connection Error: {str(e)}"}
set_header()nlp = spacy.load("en_core_web_md")7 unmodified linesif mode == "geocombo": text = params.get("text", "") st.markdown("### 🌍 Geographic Combo Mode") st.write("你选择的句子是:") st.write("The sentence you choose is:") st.write(text)
parsed_steps = llm_coding.llmapi(text) result = llm_coding.execute_steps(parsed_steps) coords = result[(max(result.keys()))] # parsed_steps = llm_coding.llmapi(text) # result = llm_coding.execute_steps(parsed_steps) # coords = result[(max(result.keys()))] # # geojson = llm_coding.get_geojson(None, coords[0], coords[1])
geojson = llm_coding.get_geojson(None, coords[0], coords[1]) geojson = call_backend(text) print(geojson, 'gggggg') draw_location(geojson) print(coords[0], coords[1], 'cccooo') # print(coords[0], coords[1], 'cccooo') print(geojson, 'ccoo')else: ent_str = params["entity"]pages/2_Tagger.py+32-7