import gradio as gr from transformers import pipeline title = "Zero-Shot Text Classification with Hugging Face" description = "bart-large-mnli" classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli") #define a function to process your input and output def zero_shot(doc, candidates): given_labels = candidates.split(", ") dictionary = classifier(doc, given_labels) labels = dictionary['labels'] scores = dictionary['scores'] return dict(zip(labels, scores)) #create input and output objects #input object1 input1 = gr.Textbox(label="Text") #input object 2 input2 = gr.Textbox(label="Labels") #output object output = gr.Label(label="Output") #example object examples = [ ["TDC A/S provides communications and entertainment solutions in Denmark. It operates through Nuuday and TDC NET segments. The company designs, builds, and operates broadband and mobile networks; and provides technical support to customers and networks. It offers services, such as landline voice, TV and streaming, broadband, Internet and network, mobility, and other services. The company provides its products and services under the YouSee, Hiper, Telmore, Blockbuster, TDC Business, TDC Erhverv, Fullrate, NetDesign, and Relatel brands. It serves consumer and business customers. The company was founded in 1882 and is based in Copenhagen, Denmark. TDC A/S is a subsidiary of DK Telekommunikation ApS.", "Diversified Telecommunication Services, Wireless Telecommunication Services, Media, Entertainment, Interactive Media and Services"], ["Giddy Inc., doing business as Boxed Wholesale, offers online wholesale and retailing services. The company provides cleaning and laundry, kitchen, paper, skin care, hair care, and grocery products. Additionally, it offers diapers and organic products. Giddy Inc. was founded in 2013 and is based in Edison, New Jersey.", "Food and Staples Retailing, Beverages, Food Products, Household Products, Personal Products, Tobacco"], ["United Iron And Steel Manufacturing Company (P.L.C.) produces and sells iron and steel products in Jordan. It is also involved in trading scrap iron. The company was incorporated in 1992 and is headquartered in Amman, Jordan. United Iron And Steel Manufacturing Company (P.L.C.) is a subsidiary of Manaseer Group Corporation.", "Chemicals, Construction Materials, Containers and Packaging, Metals and Mining, Paper and Forest Products"] ] #create interface gui = gr.Interface(title=title, description=description, fn=zero_shot, inputs=[input1, input2], outputs=[output], examples=examples) #display the interface gui.launch()