|
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") |
|
|
|
|
|
|
|
results = classifier(test_list, ['Vegetarian', 'meat']) |
|
|
|
labels = [result["labels"][0] for result in results] |
|
veg_score = labels.count("Vegetarian") |
|
|
|
|
|
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) |
|
|
|
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() |