File size: 2,115 Bytes
3b9fb2c
a508c57
3b9fb2c
a508c57
 
 
 
 
 
 
 
 
 
3d53082
 
 
c35975c
a508c57
c35975c
a508c57
3d53082
a508c57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d53082
 
a508c57
 
 
c35975c
 
a508c57
 
c35975c
306e33b
a508c57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306e33b
 
a508c57
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
from typing import Union, Dict, Any, List

# Sample pre-calculated entities
sample_text = (
    "Recent studies on ocean currents from the Global Ocean Temperature Dataset "
    "(GOTD) indicate significant shifts in marine biodiversity."
)
sample_entities = [
    {"label": "named dataset", "text": "Global Ocean Temperature Dataset", "start": 29, "end": 62, "score": 0.99},
    {"label": "acronym", "text": "GOTD", "start": 64, "end": 68, "score": 0.98},
]
rels = [
    'acronym', 'author', 'data description',
    'data geography', 'data source', 'data type',
    'publication year', 'publisher', 'reference year', 'version'
]
MODELS = ["demo-model-1", "demo-model-2"]

# Annotate_query simulation

def annotate_query(
    query: str,
    labels: Union[str, List[str]],
    threshold: float = 0.3,
    nested_ner: bool = False,
    model_name: str = None
) -> Dict[str, Any]:
    # In a real app, you'd call parse_query/inference_pipeline here.
    # For simulation, reuse sample_entities.
    return {
        "text": query,
        "entities": [
            {"start": ent["start"], "end": ent["end"], "label": ent["label"]}
            for ent in sample_entities
        ]
    }

# Build Gradio UI
demo = gr.Blocks()
with demo:
    gr.Markdown(
        """
        ## Step: Annotate Query Simulation
        Enter text (prepopulated) and click **Annotate** to see how entities are highlighted.
        """
    )
    # Inputs
    query = gr.Textbox(lines=3, value=sample_text, label="Input Text")
    entities = gr.Textbox(value=", ".join(rels), label="Relations (unused in simulation)")
    threshold = gr.Slider(0, 1, value=0.3, step=0.01, label="Threshold")
    nested = gr.Checkbox(value=False, label="Nested NER")
    model = gr.Radio(choices=MODELS, value=MODELS[0], label="Model")

    # Outputs
    output_hl = gr.HighlightedText(label="Annotated Entities")

    # Button
    annotate_btn = gr.Button("Annotate")
    annotate_btn.click(
        fn=annotate_query,
        inputs=[query, entities, threshold, nested, model],
        outputs=[output_hl]
    )

demo.launch(debug=True)