import gradio as gr def what_happened(text, file_object, option_list): if file_object: output = "You uploaded a file." if len(option_list) > 0: output = output + "\nYou selected these options:\n- " + "\n- ".join(option_list) else: output = "Normally, this demo should analyse the emotions in this text:\n" + text if len(option_list) > 0: output = output + "\nYou can only select options when uploading a dataset." return output def what_happened1(text): output = "Normally, this demo should analyse the emotions in this text:\n" + text return output def what_happened2(file_object, option_list): if file_object: output = "You uploaded a file." if len(option_list) > 0: output = output + "\nYou selected these options:\n- " + "\n- ".join(option_list) else: output = "You should upload a file." return output iface0 = gr.Interface( fn=what_happened, inputs=[ gr.Textbox( label= "Enter a sentence", lines=1, value="Your name"), gr.File( label="Or upload a dataset"), gr.CheckboxGroup( ["emotion frequencies", "emotion distribution over time", "peaks", "topics"], label = "Select options") ], outputs="text") iface1 = gr.Interface( fn=what_happened1, gr.Textbox( label= "Enter a sentence", lines=1, value="Your name") outputs="text") iface2 = gr.Interface( fn=what_happened2, inputs=[ gr.File( label="Upload a dataset"), gr.CheckboxGroup( ["emotion frequencies", "emotion distribution over time", "peaks", "topics"], label = "Select options") ], outputs="text") iface = gr.TabbedInterface([iface1, iface2], ["Sentence", "Dataset"]) iface.launch()