Spaces:
Sleeping
Sleeping
Shunfeng Zheng commited on
Update pages/2_Tagger.py
Browse files17 unmodified lines18192021222324277 unmodified lines30230330430530630729 unmodified lines3373383393403413427 unmodified lines35035135235335435535635735835936036136236336436536617 unmodified linesfrom streamlit.components.v1 import htmlfrom spacy.tokens import Span, Docfrom utils import llm_codingdef nav_page(page_name, timeout_secs=3):277 unmodified linesdef draw_location(geojson):#gj = json.load(geojson)centroid = geojson['features'][0]['properties']['centroid']centroid = (centroid[0],centroid[1])my_map = folium.Map(location=[centroid[1], centroid[0]],29 unmodified linesend = start + len(text)return Span(doc, doc.char_span(start, end, label=label).start, doc.char_span(start, end, label=label).end, label=label)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(text)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])draw_location(geojson)print(coords[0], coords[1], 'cccooo')print(geojson, 'ccoo')else:ent_str = params["entity"]17 unmodified lines18192021222324277 unmodified lines30230330430530630730829 unmodified lines3383393403413423433443453463473483493503513523533543553563573583593603613623633647 unmodified lines37237337437537637737837938038138238338438538638738838939039117 unmodified linesfrom streamlit.components.v1 import htmlfrom spacy.tokens import Span, Docfrom utils import llm_codingimport osdef nav_page(page_name, timeout_secs=3):277 unmodified linesdef 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 linesend = 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("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()))]## 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(geojson, 'ccoo')else:ent_str = params["entity"]
pages/2_Tagger.py+32-7