etadevosyan commited on
Commit
8af4fc3
·
1 Parent(s): fbc420b

Changed layout

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -11,29 +11,37 @@ tokenizer_cat = BertTokenizer.from_pretrained("warleagle/service_name_categorize
11
  token=HF_TOKEN)
12
  model_cat = BertForSequenceClassification.from_pretrained('warleagle/service_name_categorizer',token=HF_TOKEN)
13
 
 
 
 
 
14
  tokenizer_spec = BertTokenizer.from_pretrained("warleagle/specialists_categorizer_model",
15
  token=HF_TOKEN)
16
  model_spec = BertForSequenceClassification.from_pretrained('warleagle/specialists_categorizer_model',token=HF_TOKEN)
17
 
 
 
 
18
  def categoriser_predict(input_text):
19
- clf = pipeline("text-classification", model=model_cat, tokenizer=tokenizer_cat)
20
- predictions = clf(input_text)
21
  numeric_label = int(predictions[0]['label'].split("_")[1])
22
- id2label = pd.read_pickle('id2label_service_categoriser.pickle')
23
- text_label = id2label[numeric_label]
24
  return text_label
25
  def doctor_spec_predict(input_text):
26
- clf = pipeline("text-classification", model=model_spec, tokenizer=tokenizer_spec)
27
- predictions = clf(input_text)
28
  numeric_label = int(predictions[0]['label'].split("_")[1])
29
- id2label = pd.read_pickle('id2label_spec_categoriser.pickle')
30
- text_label = id2label[numeric_label]
31
  return text_label
32
  def dops_predict(input_text):
33
  cfg = ServiceDopsConfig()
34
  model = DopsClassifier(config=cfg)
35
  result = model.run_all_dops(input_text)
36
  return result
 
 
 
 
 
37
  def service_pipeline(input_text):
38
  categoriser_result = categoriser_predict(input_text)
39
  if categoriser_result!='Консультация специалиста':
@@ -42,15 +50,21 @@ def service_pipeline(input_text):
42
  doctor_spec_result = doctor_spec_predict(input_text)
43
  dops_result = dops_predict(input_text)
44
  dops_result = json.dumps(dops_result,indent=4,ensure_ascii=False)
45
- return categoriser_result,doctor_spec_result,dops_result
 
46
  demo = gr.Interface(fn=service_pipeline,inputs=gr.components.Textbox(label='Название услуги'),
47
  outputs=[gr.components.Textbox(label='Относится ли данная услуга к приёму специалиста'),
48
  gr.components.Textbox(label='Специальность врача'),
49
- gr.Textbox(label='Дополнительные параметры услуги')],
 
 
 
 
50
  examples=[
51
  ['Врач-офтальмолог (высшая категория/кандидат медицинских наук), первичный приём'],
52
  ['Прием (осмотр, консультация) - врача -оториноларинголога Первичный, рекомендации'],
53
- ['Прием врача специалиста ЛОР']])
 
54
 
55
  if __name__ == "__main__":
56
  demo.launch()
 
11
  token=HF_TOKEN)
12
  model_cat = BertForSequenceClassification.from_pretrained('warleagle/service_name_categorizer',token=HF_TOKEN)
13
 
14
+ clf_cat = pipeline("text-classification", model=model_cat, tokenizer=tokenizer_cat)
15
+
16
+ id2label_cat = pd.read_pickle('id2label_service_categoriser.pickle')
17
+
18
  tokenizer_spec = BertTokenizer.from_pretrained("warleagle/specialists_categorizer_model",
19
  token=HF_TOKEN)
20
  model_spec = BertForSequenceClassification.from_pretrained('warleagle/specialists_categorizer_model',token=HF_TOKEN)
21
 
22
+ clf_spec = pipeline("text-classification", model=model_spec, tokenizer=tokenizer_spec)
23
+
24
+ id2label_spec = pd.read_pickle('id2label_spec_categoriser.pickle')
25
  def categoriser_predict(input_text):
26
+ predictions = clf_cat(input_text)
 
27
  numeric_label = int(predictions[0]['label'].split("_")[1])
28
+ text_label = id2label_cat[numeric_label]
 
29
  return text_label
30
  def doctor_spec_predict(input_text):
31
+ predictions = clf_spec(input_text)
 
32
  numeric_label = int(predictions[0]['label'].split("_")[1])
33
+ text_label = id2label_spec[numeric_label]
 
34
  return text_label
35
  def dops_predict(input_text):
36
  cfg = ServiceDopsConfig()
37
  model = DopsClassifier(config=cfg)
38
  result = model.run_all_dops(input_text)
39
  return result
40
+ def convert_dops_to_dif_fields(dops_result):
41
+ dops_values = []
42
+ for dop in dops_result:
43
+ dops_values.append(dop['values'])
44
+ return dops_values
45
  def service_pipeline(input_text):
46
  categoriser_result = categoriser_predict(input_text)
47
  if categoriser_result!='Консультация специалиста':
 
50
  doctor_spec_result = doctor_spec_predict(input_text)
51
  dops_result = dops_predict(input_text)
52
  dops_result = json.dumps(dops_result,indent=4,ensure_ascii=False)
53
+ dops_values = convert_dops_to_dif_fields(dops_result)
54
+ return categoriser_result,doctor_spec_result,dops_values[0],dops_values[1],dops_values[2],dops_values[3],dops_values[5]
55
  demo = gr.Interface(fn=service_pipeline,inputs=gr.components.Textbox(label='Название услуги'),
56
  outputs=[gr.components.Textbox(label='Относится ли данная услуга к приёму специалиста'),
57
  gr.components.Textbox(label='Специальность врача'),
58
+ gr.components.Textbox(label='Место оказания услуги'),
59
+ gr.components.Textbox(label='Учёная степень'),
60
+ gr.components.Textbox(label='Возрастная категория'),
61
+ gr.components.Textbox(label='Вид приёма'),
62
+ gr.components.Textbox(label='Расстояние в км от М(КАД)')],
63
  examples=[
64
  ['Врач-офтальмолог (высшая категория/кандидат медицинских наук), первичный приём'],
65
  ['Прием (осмотр, консультация) - врача -оториноларинголога Первичный, рекомендации'],
66
+ ['Прием врача специалиста ЛОР'],
67
+ ['Прием (осмотр, консультация) врача-терапевта на дому, повторный (в пределах 5 км от М(КАД)/административной границы города)']])
68
 
69
  if __name__ == "__main__":
70
  demo.launch()