NomClass / app.py
hh1199's picture
Update app.py
eca5009 verified
raw
history blame
942 Bytes
import gradio as gr
from transformers import pipeline
# Используем проверенную модель
classifier = pipeline(
"zero-shot-classification",
model="cointegrated/rubert-tiny2",
device=-1
)
def classify(item: str, categories: str) -> str:
categories_list = [c.strip() for c in categories.split(",")]
result = classifier(
item,
candidate_labels=categories_list,
multi_label=False
)
return f"{result['labels'][0]} (score: {result['scores'][0]:.2f})"
iface = gr.Interface(
fn=classify,
inputs=[
gr.Textbox(label="Товар"),
gr.Textbox(label="Категории", value="Инструменты, Овощи, Техника")
],
outputs=gr.Textbox(label="Результат"),
examples=[
["Молоток", "Инструменты, Овощи"],
["Морковь", "Овощи, Фрукты"]
]
)
iface.launch()