|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
classifier = pipeline("text-classification", model="cointegrated/rubert-tiny2") |
|
|
|
|
|
CATEGORIES = ["Овощи", "Инструменты", "Фрукты"] |
|
|
|
def classify(item: str, categories: list) -> str: |
|
prompt = f"Отнеси '{item}' к категории: {', '.join(categories)}. Ответь только категорией." |
|
result = classifier(prompt, truncation=True) |
|
|
|
|
|
label_index = int(result[0]['label'].split("_")[1]) |
|
return CATEGORIES[label_index] |
|
|
|
|
|
iface = gr.Interface( |
|
fn=classify, |
|
inputs=[ |
|
gr.Textbox(label="Название товара"), |
|
gr.Textbox(label="Категории (через запятую)", value="Овощи, Инструменты, Коробки") |
|
], |
|
outputs=gr.Textbox(label="Категория") |
|
) |
|
|
|
iface.launch() |