File size: 1,190 Bytes
703a85e
47a7d13
703a85e
81eb679
47a7d13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import evaluate
import gradio as gr

module = evaluate.load("Bekhouche/NED")

def compute_ned(dataframe):
    predictions = dataframe['Predictions'].tolist()
    references = dataframe['References'].tolist()
    if len(predictions) != len(references):
        return "Error: Number of predictions and references must match!"
    module.add_batch(predictions=predictions, references=references)
    result = module.compute()
    return result

def custom_launch_gradio_widget(module):
    metric_info = module._info()
    
    with gr.Blocks() as demo:
        gr.Markdown(f"### {metric_info.description}")
        gr.Markdown(f"**Citation:** {metric_info.citation}")
        gr.Markdown(f"**Inputs Description:** {metric_info.inputs_description}")

        input_data = gr.Dataframe(
            headers=["Predictions", "References"],
            row_count=1,
            label="Input Predictions and References"
        )

        run_button = gr.Button("Run NED")
        output = gr.Textbox(label="NED Score")

        run_button.click(
            compute_ned,
            inputs=input_data,
            outputs=output,
        )

    demo.launch()

custom_launch_gradio_widget(module)