Spaces:
Running
Running
Shunfeng Zheng
commited on
Update pages/2_Tagger.py
Browse files- pages/2_Tagger.py +32 -7
pages/2_Tagger.py
CHANGED
@@ -18,7 +18,7 @@ from geocoder import geo_level3
|
|
18 |
from streamlit.components.v1 import html
|
19 |
from spacy.tokens import Span, Doc
|
20 |
from utils import llm_coding
|
21 |
-
|
22 |
|
23 |
|
24 |
def nav_page(page_name, timeout_secs=3):
|
@@ -302,6 +302,7 @@ def set_map_menu():
|
|
302 |
|
303 |
def draw_location(geojson):
|
304 |
#gj = json.load(geojson)
|
|
|
305 |
centroid = geojson['features'][0]['properties']['centroid']
|
306 |
centroid = (centroid[0],centroid[1])
|
307 |
my_map = folium.Map(location=[centroid[1], centroid[0]],
|
@@ -337,6 +338,27 @@ def create_span(doc, text, label="ENTITY"):
|
|
337 |
end = start + len(text)
|
338 |
return Span(doc, doc.char_span(start, end, label=label).start, doc.char_span(start, end, label=label).end, label=label)
|
339 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
|
341 |
set_header()
|
342 |
nlp = spacy.load("en_core_web_md")
|
@@ -350,17 +372,20 @@ mode = params.get("mode", None)
|
|
350 |
if mode == "geocombo":
|
351 |
text = params.get("text", "")
|
352 |
st.markdown("### 🌍 Geographic Combo Mode")
|
353 |
-
st.write("
|
354 |
st.write(text)
|
355 |
|
356 |
|
357 |
-
parsed_steps = llm_coding.llmapi(text)
|
358 |
-
result = llm_coding.execute_steps(parsed_steps)
|
359 |
-
coords = result[(max(result.keys()))]
|
|
|
|
|
360 |
|
361 |
-
geojson =
|
|
|
362 |
draw_location(geojson)
|
363 |
-
print(coords[0], coords[1], 'cccooo')
|
364 |
print(geojson, 'ccoo')
|
365 |
else:
|
366 |
ent_str = params["entity"]
|
|
|
18 |
from streamlit.components.v1 import html
|
19 |
from spacy.tokens import Span, Doc
|
20 |
from utils import llm_coding
|
21 |
+
import os
|
22 |
|
23 |
|
24 |
def nav_page(page_name, timeout_secs=3):
|
|
|
302 |
|
303 |
def draw_location(geojson):
|
304 |
#gj = json.load(geojson)
|
305 |
+
geojson = geojson['data'][0]
|
306 |
centroid = geojson['features'][0]['properties']['centroid']
|
307 |
centroid = (centroid[0],centroid[1])
|
308 |
my_map = folium.Map(location=[centroid[1], centroid[0]],
|
|
|
338 |
end = start + len(text)
|
339 |
return Span(doc, doc.char_span(start, end, label=label).start, doc.char_span(start, end, label=label).end, label=label)
|
340 |
|
341 |
+
API_TOKEN = os.getenv('API_TOKEN2')
|
342 |
+
|
343 |
+
BACKEND_URL = "https://dsbb0707-dockerb21.hf.space/api/predict/"
|
344 |
+
|
345 |
+
import requests
|
346 |
+
def call_backend(input_text):
|
347 |
+
try:
|
348 |
+
headers = {
|
349 |
+
"Authorization": f"Bearer {API_TOKEN}"
|
350 |
+
}
|
351 |
+
response = requests.post(
|
352 |
+
BACKEND_URL,
|
353 |
+
headers=headers,
|
354 |
+
json={"data": [input_text]},
|
355 |
+
timeout=10
|
356 |
+
)
|
357 |
+
if response.status_code == 200:
|
358 |
+
return response.json() # ✅ 保留原始 JSON 对象 (dict)
|
359 |
+
return {"error": f"❌ Backend Error (HTTP {response.status_code})"}
|
360 |
+
except Exception as e:
|
361 |
+
return {"error": f"⚠️ Connection Error: {str(e)}"}
|
362 |
|
363 |
set_header()
|
364 |
nlp = spacy.load("en_core_web_md")
|
|
|
372 |
if mode == "geocombo":
|
373 |
text = params.get("text", "")
|
374 |
st.markdown("### 🌍 Geographic Combo Mode")
|
375 |
+
st.write("The sentence you choose is:")
|
376 |
st.write(text)
|
377 |
|
378 |
|
379 |
+
# parsed_steps = llm_coding.llmapi(text)
|
380 |
+
# result = llm_coding.execute_steps(parsed_steps)
|
381 |
+
# coords = result[(max(result.keys()))]
|
382 |
+
#
|
383 |
+
# geojson = llm_coding.get_geojson(None, coords[0], coords[1])
|
384 |
|
385 |
+
geojson = call_backend(text)
|
386 |
+
print(geojson, 'gggggg')
|
387 |
draw_location(geojson)
|
388 |
+
# print(coords[0], coords[1], 'cccooo')
|
389 |
print(geojson, 'ccoo')
|
390 |
else:
|
391 |
ent_str = params["entity"]
|