File size: 2,011 Bytes
74aa6b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f577279
 
 
 
 
 
 
 
 
 
 
 
 
74aa6b2
 
 
 
 
 
 
 
 
 
 
 
 
f577279
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74aa6b2
 
 
 
 
 
 
 
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
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse

import gradio as gr
import platform


def get_args():
    parser = argparse.ArgumentParser()

    args = parser.parse_args()
    return args


model_names = {
    "allennlp_text_classification": {
        "qgyd2021/language_identification": "https://huggingface.co/qgyd2021/language_identification"
    }
}


def click_button_allennlp_text_classification(text: str, model_name: str):
    print(text)
    print(model_name)
    return "label", 0.0


def main():
    args = get_args()

    brief_description = """
    ## NLP Tools

    NLP Tools Demo
    """

    # ui
    with gr.Blocks() as blocks:
        gr.Markdown(value=brief_description)

        with gr.Tabs():
            with gr.TabItem("AllenNLP Text Classification"):
                with gr.Row():
                    with gr.Column(scale=3):
                        text = gr.Text(label="text")
                        ground_true = gr.Text(label="ground_true")
                        model_name = gr.Dropdown(
                            choices=list(model_names["allennlp_text_classification"].keys())
                        )
                        button = gr.Button("infer", variant="primary")

                    with gr.Column(scale=3):
                        label = gr.Text(label="label")
                        prob = gr.Text(label="prob")

                gr.Examples(
                    examples=[
                        ["你好", "zh", "qgyd2021/language_identification"]
                    ],
                    inputs=[text, ground_true, model_name],
                    outputs=[label, prob],
                )
                button.click(
                    click_button_allennlp_text_classification,
                    inputs=[text, model_name],
                    outputs=[label, prob]
                )

    blocks.queue().launch(
        share=False if platform.system() == "Windows" else False
    )
    return


if __name__ == '__main__':
    main()