Spaces:
Running
Running
Commit
·
d64d47b
1
Parent(s):
aa04021
wqewqewqe
Browse files
app.py
CHANGED
@@ -1,54 +1,51 @@
|
|
1 |
import re
|
2 |
import gradio as gr
|
3 |
|
4 |
-
# Simulated GLiNER output
|
5 |
-
|
6 |
"Household Survey Data": "named dataset",
|
7 |
"Ethiopia": "data geography",
|
8 |
"2020": "reference year",
|
9 |
"World Bank": "publisher"
|
10 |
}
|
11 |
|
12 |
-
def
|
13 |
-
"""
|
14 |
-
Return a dict with the original text and a list of start/end/label spans.
|
15 |
-
"""
|
16 |
entities = []
|
17 |
-
for phrase, label in
|
18 |
-
# find all occurrences of phrase
|
19 |
for m in re.finditer(re.escape(phrase), text):
|
20 |
entities.append({
|
21 |
-
"
|
22 |
-
"
|
23 |
-
"
|
24 |
})
|
25 |
return {"text": text, "entities": entities}
|
26 |
|
27 |
with gr.Blocks() as demo:
|
28 |
-
gr.Markdown("## Simulated GLiNER
|
29 |
-
"Type
|
30 |
-
|
31 |
-
|
32 |
-
label="Input Text",
|
33 |
lines=3,
|
34 |
-
value="The Household Survey Data for Ethiopia in 2020 was published by the World Bank."
|
|
|
|
|
35 |
)
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
#
|
40 |
-
|
41 |
-
|
42 |
-
#
|
43 |
-
demo.load(fn=
|
44 |
-
|
45 |
gr.Markdown("""
|
46 |
-
**
|
47 |
-
- **named dataset
|
48 |
-
- **data geography
|
49 |
-
- **reference year
|
50 |
-
- **publisher
|
51 |
""")
|
52 |
|
53 |
if __name__ == "__main__":
|
54 |
-
demo.launch(
|
|
|
1 |
import re
|
2 |
import gradio as gr
|
3 |
|
4 |
+
# Simulated GLiNER‐style output
|
5 |
+
SIM_ENTITIES = {
|
6 |
"Household Survey Data": "named dataset",
|
7 |
"Ethiopia": "data geography",
|
8 |
"2020": "reference year",
|
9 |
"World Bank": "publisher"
|
10 |
}
|
11 |
|
12 |
+
def annotate_text(text):
|
|
|
|
|
|
|
13 |
entities = []
|
14 |
+
for phrase, label in SIM_ENTITIES.items():
|
|
|
15 |
for m in re.finditer(re.escape(phrase), text):
|
16 |
entities.append({
|
17 |
+
"entity": label, # note: 'entity' key
|
18 |
+
"start": m.start(),
|
19 |
+
"end": m.end(),
|
20 |
})
|
21 |
return {"text": text, "entities": entities}
|
22 |
|
23 |
with gr.Blocks() as demo:
|
24 |
+
gr.Markdown("## Simulated GLiNER Highlighter\n"
|
25 |
+
"Type or paste a sentence and click **Highlight**.")
|
26 |
+
|
27 |
+
txt = gr.Textbox(
|
|
|
28 |
lines=3,
|
29 |
+
value="The Household Survey Data for Ethiopia in 2020 was published by the World Bank.",
|
30 |
+
label="Input Text",
|
31 |
+
placeholder="Enter any sentence here…"
|
32 |
)
|
33 |
+
btn = gr.Button("Highlight")
|
34 |
+
out = gr.HighlightedText(label="Annotated Entities")
|
35 |
+
|
36 |
+
# fire on button click or Enter
|
37 |
+
btn.click(fn=annotate_text, inputs=txt, outputs=out)
|
38 |
+
txt.submit(fn=annotate_text, inputs=txt, outputs=out)
|
39 |
+
# initial render
|
40 |
+
demo.load(fn=annotate_text, inputs=txt, outputs=out)
|
41 |
+
|
42 |
gr.Markdown("""
|
43 |
+
**Legend**
|
44 |
+
- **named dataset** → Household Survey Data
|
45 |
+
- **data geography** → Ethiopia
|
46 |
+
- **reference year** → 2020
|
47 |
+
- **publisher** → World Bank
|
48 |
""")
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
+
demo.launch(debug=True)
|