''' Author: Qiguang Chen LastEditors: Qiguang Chen Date: 2023-02-07 15:42:32 LastEditTime: 2023-02-19 21:04:03 Description: ''' import argparse import gradio as gr from common.config import Config from common.model_manager import ModelManager from common.utils import str2bool parser = argparse.ArgumentParser() parser.add_argument('--config_path', '-cp', type=str, default="config/examples/from_pretrained.yaml") parser.add_argument('--push_to_public', '-p', type=str2bool, nargs='?', const=True, default=False, help="Push to public network.") args = parser.parse_args() config = Config.load_from_yaml(args.config_path) config.base["train"] = False config.base["test"] = False model_manager = ModelManager(config) model_manager.init_model() def text_analysis(text): print(text) data = model_manager.predict(text) html = """ """ html += """
Intent:""" for intent in data["intent"]: html += """""" html += """
Slot:""" for t, slot in zip(data["text"], data["slot"]): html += """""" html+="
" return html demo = gr.Interface( text_analysis, gr.Textbox(placeholder="Enter sentence here..."), ["html"], examples=[ ["i would like to find a flight from charlotte to las vegas that makes a stop in st louis"], ], ) if args.push_to_public: demo.launch(share=True) else: demo.launch()