Spaces:
Sleeping
Sleeping
maximuspowers
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -47,7 +47,7 @@ def post_process_entities(result):
|
|
47 |
token_data["labels"] = new_labels
|
48 |
return result
|
49 |
|
50 |
-
# Generate JSON results with probabilities
|
51 |
def predict_ner_tags_with_json(sentence):
|
52 |
inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
53 |
input_ids = inputs['input_ids'].to(model.device)
|
@@ -134,7 +134,10 @@ def predict_ner_tags_with_json(sentence):
|
|
134 |
</table>
|
135 |
"""
|
136 |
|
137 |
-
|
|
|
|
|
|
|
138 |
|
139 |
# Gradio Interface
|
140 |
iface = gr.Blocks()
|
@@ -158,7 +161,7 @@ with iface:
|
|
158 |
with gr.Row():
|
159 |
input_box = gr.Textbox(label="Input Sentence")
|
160 |
with gr.Row():
|
161 |
-
output_box = gr.HTML(label="Entity Matrix")
|
162 |
|
163 |
input_box.change(predict_ner_tags_with_json, inputs=[input_box], outputs=[output_box])
|
164 |
|
|
|
47 |
token_data["labels"] = new_labels
|
48 |
return result
|
49 |
|
50 |
+
# Generate HTML matrix and JSON results with probabilities
|
51 |
def predict_ner_tags_with_json(sentence):
|
52 |
inputs = tokenizer(sentence, return_tensors="pt", padding=True, truncation=True, max_length=128)
|
53 |
input_ids = inputs['input_ids'].to(model.device)
|
|
|
134 |
</table>
|
135 |
"""
|
136 |
|
137 |
+
# JSON string
|
138 |
+
json_result = json.dumps(result, indent=4)
|
139 |
+
|
140 |
+
return f"{matrix_html}<br><pre>{json_result}</pre>"
|
141 |
|
142 |
# Gradio Interface
|
143 |
iface = gr.Blocks()
|
|
|
161 |
with gr.Row():
|
162 |
input_box = gr.Textbox(label="Input Sentence")
|
163 |
with gr.Row():
|
164 |
+
output_box = gr.HTML(label="Entity Matrix and JSON Output")
|
165 |
|
166 |
input_box.change(predict_ner_tags_with_json, inputs=[input_box], outputs=[output_box])
|
167 |
|