DmitriySv commited on
Commit
64b4c39
·
verified ·
1 Parent(s): e237ca9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import BertTokenizer, BertForSequenceClassification
3
+ import torch
4
+
5
+ model = BertForSequenceClassification.from_pretrained("DmitriySv/ticket_classifier")
6
+ tokenizer = BertTokenizer.from_pretrained("DmitriySv/ticket_classifier")
7
+
8
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
9
+ model = model.to(device)
10
+ model.eval()
11
+
12
+ def classify(text):
13
+ inputs = tokenizer(text, padding=True, truncation=True, max_length=512, return_tensors="pt").to(device)
14
+
15
+ with torch.no_grad():
16
+ logits_task1, logits_task2 = model(**inputs)
17
+
18
+ pred_task1 = torch.argmax(logits_task1, dim=1).item()
19
+ pred_task2 = torch.argmax(logits_task2, dim=1).item()
20
+
21
+ return {"Тип": pred_task1, "Приоритет": pred_task2}
22
+
23
+ interface = gr.Interface(
24
+ fn=classify,
25
+ inputs=gr.Textbox(label="Введите запрос для классификации"),
26
+ outputs=[gr.Label(label="Тип"), gr.Label(label="Приоритет")],
27
+ title="Классификация запроса по типу и приоритету",
28
+ description="Классификация запроса по типу и приоритету."
29
+ )
30
+
31
+ interface.launch()