Spaces:
Running
Running
Shunfeng Zheng
commited on
Update 1_SpatialParse.py
Browse files- 1_SpatialParse.py +21 -21
1_SpatialParse.py
CHANGED
@@ -11,27 +11,27 @@ from spacy.tokens import Span, Doc, Token
|
|
11 |
from utils import geoutil
|
12 |
import urllib.parse
|
13 |
import os
|
14 |
-
import requests
|
15 |
|
16 |
API_TOKEN = os.getenv("HF_API_TOKEN")
|
17 |
BACKEND_URL = "https://dsbb0707-dockerb2.hf.space/api/predict/"
|
18 |
-
def call_backend(input_text):
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
|
36 |
|
37 |
colors = {'GPE': "#43c6fc", "LOC": "#fd9720", "RSE":"#a6e22d"}
|
@@ -224,9 +224,9 @@ def extract_spatial_entities(text):
|
|
224 |
# # doc.to_disk("saved_doc.spacy")
|
225 |
# doc.to_disk("/tmp/saved_doc.spacy")
|
226 |
|
227 |
-
api_result = call_backend(text)
|
228 |
-
st.markdown(api_result)
|
229 |
-
st.text_area(api_result)
|
230 |
|
231 |
# html = displacy.render(doc,style="ent", options = options)
|
232 |
# html = html.replace("\n","")
|
|
|
11 |
from utils import geoutil
|
12 |
import urllib.parse
|
13 |
import os
|
14 |
+
# import requests
|
15 |
|
16 |
API_TOKEN = os.getenv("HF_API_TOKEN")
|
17 |
BACKEND_URL = "https://dsbb0707-dockerb2.hf.space/api/predict/"
|
18 |
+
# def call_backend(input_text):
|
19 |
+
# try:
|
20 |
+
# headers = {
|
21 |
+
# "Authorization": f"Bearer {API_TOKEN}"
|
22 |
+
# }
|
23 |
+
# response = requests.post(
|
24 |
+
# BACKEND_URL,
|
25 |
+
# headers=headers,
|
26 |
+
# json={"data": [input_text]},
|
27 |
+
# timeout=10
|
28 |
+
# )
|
29 |
+
# if response.status_code == 200:
|
30 |
+
# result = response.json()["data"][0]
|
31 |
+
# return f"✅ {result['result']}\n⏰ {result['timestamp']}"
|
32 |
+
# return f"❌ Backend Error (HTTP {response.status_code})"
|
33 |
+
# except Exception as e:
|
34 |
+
# return f"⚠️ Connection Error: {str(e)}"
|
35 |
|
36 |
|
37 |
colors = {'GPE': "#43c6fc", "LOC": "#fd9720", "RSE":"#a6e22d"}
|
|
|
224 |
# # doc.to_disk("saved_doc.spacy")
|
225 |
# doc.to_disk("/tmp/saved_doc.spacy")
|
226 |
|
227 |
+
# api_result = call_backend(text)
|
228 |
+
# st.markdown(api_result)
|
229 |
+
# st.text_area(api_result)
|
230 |
|
231 |
# html = displacy.render(doc,style="ent", options = options)
|
232 |
# html = html.replace("\n","")
|