File size: 1,560 Bytes
fd0fe48
3b9fb2c
 
d64d47b
 
fd0fe48
ab9767d
 
 
fd0fe48
c35975c
d64d47b
fd0fe48
d64d47b
ab9767d
fd0fe48
d64d47b
 
 
fd0fe48
 
3d53082
fd0fe48
d64d47b
 
 
 
fd0fe48
d64d47b
 
 
306e33b
d64d47b
 
 
 
 
 
 
 
 
fd0fe48
d64d47b
 
 
 
 
fd0fe48
306e33b
fd0fe48
d64d47b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import re
import gradio as gr

# Simulated GLiNER‐style output
SIM_ENTITIES = {
    "Household Survey Data": "named dataset",
    "Ethiopia":             "data geography",
    "2020":                 "reference year",
    "World Bank":           "publisher"
}

def annotate_text(text):
    entities = []
    for phrase, label in SIM_ENTITIES.items():
        for m in re.finditer(re.escape(phrase), text):
            entities.append({
                "entity": label,    # note: 'entity' key
                "start":  m.start(),
                "end":    m.end(),
            })
    return {"text": text, "entities": entities}

with gr.Blocks() as demo:
    gr.Markdown("## Simulated GLiNER Highlighter\n"
                "Type or paste a sentence and click **Highlight**.")

    txt = gr.Textbox(
        lines=3,
        value="The Household Survey Data for Ethiopia in 2020 was published by the World Bank.",
        label="Input Text",
        placeholder="Enter any sentence here…"
    )
    btn = gr.Button("Highlight")
    out = gr.HighlightedText(label="Annotated Entities")

    # fire on button click or Enter
    btn.click(fn=annotate_text, inputs=txt, outputs=out)
    txt.submit(fn=annotate_text, inputs=txt, outputs=out)
    # initial render
    demo.load(fn=annotate_text, inputs=txt, outputs=out)

    gr.Markdown("""
**Legend**  
- **named dataset** → Household Survey Data  
- **data geography** → Ethiopia  
- **reference year** → 2020  
- **publisher** → World Bank
""")

if __name__ == "__main__":
    demo.launch(debug=True)