Update app.py
Browse files
app.py
CHANGED
@@ -108,7 +108,6 @@ examples = [
|
|
108 |
|
109 |
|
110 |
def ner(text: str, labels: str, threshold: float, nested_ner: bool) -> Dict[str, Union[str, int, float]]:
|
111 |
-
labels = labels.split(",")
|
112 |
return [
|
113 |
{
|
114 |
"entity": entity["label"],
|
@@ -117,7 +116,7 @@ def ner(text: str, labels: str, threshold: float, nested_ner: bool) -> Dict[str,
|
|
117 |
"end": entity["end"],
|
118 |
}
|
119 |
for entity in model.predict_entities(
|
120 |
-
text, labels, flat_ner=not nested_ner, threshold=threshold
|
121 |
)
|
122 |
]
|
123 |
|
@@ -154,9 +153,9 @@ demo = gr.Interface(
|
|
154 |
|
155 |
app = FastAPI()
|
156 |
|
157 |
-
@app.get("/
|
158 |
-
def read_main(text: str = ""):
|
159 |
-
predict_response = requests.post('http://localhost:7860/call/predict', json={'data': [text,
|
160 |
if "event_id" not in predict_response:
|
161 |
return predict_response
|
162 |
return json.loads(requests.get(f'http://localhost:7860/call/predict/{predict_response["event_id"]}').text.split("data: ", 1)[-1])
|
|
|
108 |
|
109 |
|
110 |
def ner(text: str, labels: str, threshold: float, nested_ner: bool) -> Dict[str, Union[str, int, float]]:
|
|
|
111 |
return [
|
112 |
{
|
113 |
"entity": entity["label"],
|
|
|
116 |
"end": entity["end"],
|
117 |
}
|
118 |
for entity in model.predict_entities(
|
119 |
+
text, [label.strip() for label in labels.split(",")], flat_ner=not nested_ner, threshold=threshold
|
120 |
)
|
121 |
]
|
122 |
|
|
|
153 |
|
154 |
app = FastAPI()
|
155 |
|
156 |
+
@app.get("/predict")
|
157 |
+
def read_main(text: str = "", labels: str = "", threshold: float = 0.3, nested_ner: bool = False):
|
158 |
+
predict_response = requests.post('http://localhost:7860/call/predict', json={'data': [text, labels, threshold, nested_ner]}).json()
|
159 |
if "event_id" not in predict_response:
|
160 |
return predict_response
|
161 |
return json.loads(requests.get(f'http://localhost:7860/call/predict/{predict_response["event_id"]}').text.split("data: ", 1)[-1])
|