import gradio as gr import pandas as pd from transformers import pipeline classifier = pipeline("zero-shot-classification", model="MoritzLaurer/DeBERTa-v3-base-mnli-fever-anli") def classify_menu(menu_items): test_list = menu_items.split("\n") #classify them results = classifier(test_list, ['Vegetarian', 'meat']) labels = [result["labels"][0] for result in results] veg_score = labels.count("Vegetarian") # Separate items into vegetarian and meat categories vegetarian_items = [] meat_items = [] for item, label in zip(test_list, labels): if label == "Vegetarian": vegetarian_items.append(f"🥦 {item}") else: meat_items.append(f"🍖 {item}") num_items = len(test_list) # Format the output with a vegetarian score and categorized lists output = f"🌱 Vegetarian Score: {veg_score} out of {num_items} items \n\n" output += "🥦 Vegetarian Options:\n" + "\n".join(vegetarian_items) + "\n\n" output += "🍖 Meat Options:\n" + "\n".join(meat_items) return output iface = gr.Interface(fn=classify_menu, inputs=gr.Textbox( lines=8, placeholder= "Input menu items as {menu} : {description} and ensure every new line is a new menu item.\n\nExample:\nSpicy Sesame Leaf Tofu Patties : Minced Oyster Mushrooms And Tofu Wrapped In Sesame Leaves\nMulligatawny : A Spicy Favorite Of Anglo-Indians Made Of Chicken, Red Lentils"), outputs="text") iface.launch()