Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,26 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
classifier = pipeline(
|
6 |
"zero-shot-classification",
|
7 |
-
model="cointegrated/rubert-tiny2"
|
8 |
-
device=-1
|
9 |
)
|
10 |
|
11 |
def classify(item: str, categories: str) -> str:
|
|
|
12 |
categories_list = [c.strip() for c in categories.split(",")]
|
13 |
-
result = classifier(
|
14 |
-
|
15 |
-
candidate_labels=categories_list,
|
16 |
-
multi_label=False
|
17 |
-
)
|
18 |
-
return f"{result['labels'][0]} (score: {result['scores'][0]:.2f})"
|
19 |
|
|
|
20 |
iface = gr.Interface(
|
21 |
fn=classify,
|
22 |
inputs=[
|
23 |
-
gr.Textbox(label="
|
24 |
-
gr.Textbox(label="Категории
|
25 |
],
|
26 |
-
outputs=gr.Textbox(label="Результат")
|
27 |
-
examples=[
|
28 |
-
["Молоток", "Инструменты, Овощи"],
|
29 |
-
["Морковь", "Овощи, Фрукты"]
|
30 |
-
]
|
31 |
)
|
32 |
|
33 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Инициализация модели
|
5 |
classifier = pipeline(
|
6 |
"zero-shot-classification",
|
7 |
+
model="cointegrated/rubert-tiny2"
|
|
|
8 |
)
|
9 |
|
10 |
def classify(item: str, categories: str) -> str:
|
11 |
+
# Основная логика классификации
|
12 |
categories_list = [c.strip() for c in categories.split(",")]
|
13 |
+
result = classifier(item, categories_list)
|
14 |
+
return result['labels'][0]
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# Интерфейс с минимальными элементами
|
17 |
iface = gr.Interface(
|
18 |
fn=classify,
|
19 |
inputs=[
|
20 |
+
gr.Textbox(label="Название товара"),
|
21 |
+
gr.Textbox(label="Категории через запятую")
|
22 |
],
|
23 |
+
outputs=gr.Textbox(label="Результат")
|
|
|
|
|
|
|
|
|
24 |
)
|
25 |
|
26 |
iface.launch()
|