Spaces:
Running
Running
Commit
·
215cbc3
1
Parent(s):
d8c3809
add get json
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
|
|
5 |
# Your model’s raw NER output (we trust these start/end indices)
|
6 |
ner = [
|
7 |
{
|
8 |
-
'start':
|
9 |
'end': 30,
|
10 |
'text': 'Home Visits Survey',
|
11 |
'label': 'named dataset',
|
@@ -50,22 +50,29 @@ def highlight_text(text):
|
|
50 |
})
|
51 |
return {"text": text, "entities": entities}
|
52 |
|
|
|
|
|
|
|
53 |
with gr.Blocks() as demo:
|
54 |
-
gr.Markdown("##
|
55 |
-
"
|
56 |
|
57 |
txt_in = gr.Textbox(label="Input Text", lines=4, value=SAMPLE_TEXT)
|
58 |
-
|
59 |
txt_out = gr.HighlightedText(label="Annotated Entities")
|
60 |
-
|
|
|
|
|
61 |
label="Model Predictions (JSON)",
|
62 |
-
value=json.dumps({"ner": ner, "relations": relations}, indent=2),
|
63 |
lines=15,
|
64 |
-
|
|
|
65 |
)
|
66 |
|
67 |
-
# Only trigger on
|
68 |
-
|
|
|
|
|
69 |
|
70 |
if __name__ == "__main__":
|
71 |
demo.launch()
|
|
|
5 |
# Your model’s raw NER output (we trust these start/end indices)
|
6 |
ner = [
|
7 |
{
|
8 |
+
'start': 11,
|
9 |
'end': 30,
|
10 |
'text': 'Home Visits Survey',
|
11 |
'label': 'named dataset',
|
|
|
50 |
})
|
51 |
return {"text": text, "entities": entities}
|
52 |
|
53 |
+
def get_model_predictions():
|
54 |
+
return json.dumps({"ner": ner, "relations": relations}, indent=2)
|
55 |
+
|
56 |
with gr.Blocks() as demo:
|
57 |
+
gr.Markdown("## GLiNER NER + RE Highlight & Predictions\n"
|
58 |
+
"Edit the sample text, then click **Highlight** to annotate entities, or **Get Model Predictions** to see the raw JSON.")
|
59 |
|
60 |
txt_in = gr.Textbox(label="Input Text", lines=4, value=SAMPLE_TEXT)
|
61 |
+
highlight_btn = gr.Button("Highlight")
|
62 |
txt_out = gr.HighlightedText(label="Annotated Entities")
|
63 |
+
|
64 |
+
get_pred_btn = gr.Button("Get Model Predictions")
|
65 |
+
ner_rel_box = gr.Textbox(
|
66 |
label="Model Predictions (JSON)",
|
|
|
67 |
lines=15,
|
68 |
+
value="",
|
69 |
+
interactive=False
|
70 |
)
|
71 |
|
72 |
+
# Only trigger highlighting on click
|
73 |
+
highlight_btn.click(fn=highlight_text, inputs=txt_in, outputs=txt_out)
|
74 |
+
# Only show preds on click
|
75 |
+
get_pred_btn.click(fn=get_model_predictions, inputs=None, outputs=ner_rel_box)
|
76 |
|
77 |
if __name__ == "__main__":
|
78 |
demo.launch()
|