#!/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()