import gradio as gr from inductor import BartInductor inductor = BartInductor() def bart(text): results = inductor.generate(text) #results=[(' is the capital and largest city of .', 0.0075895977795922415), (' is the largest city in .', 0.005302619071099926), (' is the most populous state in .', 0.0036559513972044544), (' is the capital of .', 0.0028800265140167813), (' is a state in .', 0.002295685033583364), (' is a capital of .', 0.001348920570936385), (' has one of the highest rates of poverty in .', 0.0012284877234430835), (' is a major commercial and financial centre of .', 0.001225910195650215), (' was then a part of .', 0.0007620440367924856), (', the capital of the country, is the largest city in .', 0.0006940517028590776)] results = [(result[0], float(result[1]) * 100) for result in results] results_dict = {result[0]: float(result[1]) for result in results} return results_dict def bart2(text): #results = inductor.generate(text) results=[(' is the capital and largest city of .', 0.0075895977795922415), (' is the largest city in .', 0.005302619071099926), (' is the most populous state in .', 0.0036559513972044544), (' is the capital of .', 0.0028800265140167813), (' is a state in .', 0.002295685033583364), (' is a capital of .', 0.001348920570936385), (' has one of the highest rates of poverty in .', 0.0012284877234430835), (' is a major commercial and financial centre of .', 0.001225910195650215), (' was then a part of .', 0.0007620440367924856), (', the capital of the country, is the largest city in .', 0.0006940517028590776)] results = [(result[0], float(result[1]) * 100) for result in results] results_dict = {result[0]: float(result[1]) for result in results} return results_dict bivar = gr.Interface(fn=bart, inputs=gr.inputs.Textbox(default=' is the capital of .'), outputs=gr.Label(), title="BART Inductor 双变量", examples=[[' is the capital of .'],[' is founder of .']], description="Enter a text prompt to generate text using BART.") trivar = gr.Interface(fn=bart2, inputs=gr.inputs.Textbox(default=' is the parent of , who is the sibling of .'), outputs=gr.Label(), title="BART Inductor 三变量", examples=[[' is the parent of , who is the sibling of .']], description="Still working on it!!!!!!!!!!!!!!!!!!!!") demo = gr.TabbedInterface([bivar, trivar], ["双变量", "三变量"]) if __name__ == "__main__": demo.launch()