Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,23 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
|
5 |
-
"
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
def classify(
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
categories_list = [c.strip() for c in categories.split(",")]
|
15 |
-
|
16 |
-
result = classifier(
|
17 |
-
item,
|
18 |
-
candidate_labels=categories_list,
|
19 |
-
hypothesis_template=hypothesis_template,
|
20 |
-
multi_label=False
|
21 |
-
)
|
22 |
-
|
23 |
-
# Возвращаем категорию с наибольшим скором
|
24 |
-
return f"{result['labels'][0]} (уверенность: {result['scores'][0]:.2f})"
|
25 |
|
26 |
-
|
27 |
fn=classify,
|
28 |
inputs=[
|
29 |
-
gr.
|
30 |
-
gr.Textbox(
|
31 |
-
|
32 |
],
|
33 |
-
outputs=gr.Textbox(
|
34 |
-
|
35 |
-
description="Введите название товара и список категорий через запятую"
|
36 |
-
)
|
37 |
-
|
38 |
-
iface.launch(debug=True)
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
models = {
|
5 |
+
"ruBert-tiny2": "cointegrated/rubert-tiny2",
|
6 |
+
"ruRoberta-large": "sberbank-ai/ruRoberta-large",
|
7 |
+
"multilingual-e5": "intfloat/multilingual-e5-base"
|
8 |
+
}
|
9 |
|
10 |
+
def classify(model, text, labels):
|
11 |
+
classifier = pipeline("zero-shot-classification", model=models[model])
|
12 |
+
result = classifier(text, [l.strip() for l in labels.split(",")])
|
13 |
+
return result['labels'][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
gr.Interface(
|
16 |
fn=classify,
|
17 |
inputs=[
|
18 |
+
gr.Dropdown(list(models.keys())),
|
19 |
+
gr.Textbox(),
|
20 |
+
gr.Textbox(value="Овощи, Инструменты, Техника")
|
21 |
],
|
22 |
+
outputs=gr.Textbox()
|
23 |
+
).launch()
|
|
|
|
|
|
|
|