File size: 2,507 Bytes
a0a66d7
 
90b5e3c
6dd01fc
a0a66d7
90b5e3c
f58c303
90b5e3c
 
6dd01fc
 
 
 
 
 
 
 
90b5e3c
0f1ad79
 
 
 
6dd01fc
0f1ad79
42a5ea2
6dd01fc
0f1ad79
 
 
 
 
 
42a5ea2
90b5e3c
1fb62f8
90b5e3c
f58c303
90b5e3c
 
 
6dd01fc
 
3fae30f
 
 
6dd01fc
3fae30f
 
6dd01fc
2c36eb0
a59c7e0
6dd01fc
f889cdb
 
 
 
 
 
 
 
0f1ad79
f58c303
a8c8670
6dd01fc
 
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
import gradio as gr

def origin_preditcion(title, context):
    return f"Title:{title}\nContext:{context}\n..."

def edit_process(title, context):
    return f"Title:{title}\nContext:{context}\n...", f"Title:{title}\nContext:{context}\n..."

def add_process(title, context, img):
    return f"Title:{title}\nContext:{context}\n...{img}"

with gr.Blocks() as demo:
    gr.Markdown("# KGE Editing")

    # 多个tab
    with gr.Tabs():

        with gr.TabItem("E-FB15k237"):
            with gr.Row():
                with gr.Column():
                    input = gr.Textbox(label="Input", lines=1, placeholder="Mask triple input")
                    origin_button = gr.Button("Origin")

                with gr.Column():
                    origin_output = gr.Textbox(label="Before Edit", lines=3, placeholder="")

            with gr.Row():
                with gr.Column():
                    alter_label = gr.Textbox(label="Alter Entity", lines=1, placeholder="Entity Name")            
                    edit_button = gr.Button("Edit", elem_id="warning")

                with gr.Column():
                    edit_output = gr.Textbox(label="After Edit", lines=3, placeholder="")
            gr.Examples(
                examples=[["[MASK] r1 t1", "h1"], ["[MASK] r2 t2", "h2"]],
                inputs=[input, alter_label],
                outputs=[origin_output, edit_output],
                fn=edit_process,
                cache_examples=True,
            )

        with gr.TabItem("A-FB15k237"):
            with gr.Row():
                with gr.Column():
                    input = gr.Textbox(label="Input", lines=1, placeholder="New triple input")

                    alter_label = gr.Textbox(label="Head/Tail", lines=1, placeholder="1:head / 0:tail")
                    add_button = gr.Button("Add")

                with gr.Column():
                    add_output = gr.Textbox(label="Add Results", lines=5, placeholder="")

            gr.Examples(
                examples=[["h1 r1 t1", "1"], ["h2 r2 t2", "1"]],
                inputs=[input, alter_label],
                outputs=add_output,
                fn=add_process,
                cache_examples=True,
            )

    origin_button.click(fn=origin_preditcion, inputs=[input, alter_label], outputs=origin_output)
    edit_button.click(fn=edit_process, inputs=[input, alter_label], outputs=[origin_output, edit_output])
    add_button.click(fn=add_process, inputs=[input, alter_label], outputs=add_output)

demo.launch()