File size: 3,202 Bytes
6371026 862f904 6802ee4 64aec53 41d6954 64aec53 527b3f6 64aec53 6371026 64aec53 6371026 c23fd35 6371026 862f904 41d6954 6371026 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
from transformers import pipeline, BertTokenizer, BertForSequenceClassification
import os
import pickle
import pandas as pd
from service_dops_api.dops_config import ServiceDopsConfig
from service_dops_api.dops_classifier import DopsClassifier
import json
HF_TOKEN = os.getenv('HF_TOKEN')
tokenizer_cat = BertTokenizer.from_pretrained("warleagle/service_name_categorizer",
token=HF_TOKEN)
model_cat = BertForSequenceClassification.from_pretrained('warleagle/service_name_categorizer',token=HF_TOKEN)
tokenizer_spec = BertTokenizer.from_pretrained("warleagle/specialists_categorizer_model",
token=HF_TOKEN)
model_spec = BertForSequenceClassification.from_pretrained('warleagle/specialists_categorizer_model',token=HF_TOKEN)
def categoriser_predict(input_text):
clf = pipeline("text-classification", model=model_cat, tokenizer=tokenizer_cat)
predictions = clf(input_text)
numeric_label = int(predictions[0]['label'].split("_")[1])
id2label = pd.read_pickle('id2label_service_categoriser.pickle')
text_label = id2label[numeric_label]
return text_label
def doctor_spec_predict(input_text):
clf = pipeline("text-classification", model=model_spec, tokenizer=tokenizer_spec)
predictions = clf(input_text)
numeric_label = int(predictions[0]['label'].split("_")[1])
id2label = pd.read_pickle('id2label_spec_categoriser.pickle')
text_label = id2label[numeric_label]
return text_label
def dops_predict(input_text):
cfg = ServiceDopsConfig()
model = DopsClassifier(config=cfg)
result = model.run_all_dops(input_text)
return result
def service_pipeline(input_text):
categoriser_result = categoriser_predict(input_text)
if categoriser_result!='Консультация специалиста':
return 'Эта услуга не относится к приему специалиста','-','-'
else:
doctor_spec_result = doctor_spec_predict(input_text)
dops_result = dops_predict(input_text)
dops_result = json.dumps(dops_result,indent=4,ensure_ascii=False)
return categoriser_result,doctor_spec_result,dops_result
demo = gr.Interface(fn=service_pipeline,inputs=gr.components.Textbox(label='Название услуги'),
outputs=[gr.components.Textbox(label='Относится ли данная услуга к приёму специалиста'),
gr.components.Textbox(label='Специальность врача'),
gr.Textbox(label='Дополнительные параметры услуги')],
examples=[
['Врач-офтальмолог (высшая категория/кандидат медицинских наук), первичный приём'],
['Прием (осмотр, консультация) - врача -оториноларинголога Первичный, рекомендации'],
['Прием врача специалиста ЛОР']])
if __name__ == "__main__":
demo.launch() |