-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaibot.py
More file actions
52 lines (40 loc) · 1.57 KB
/
aibot.py
File metadata and controls
52 lines (40 loc) · 1.57 KB
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
from __future__ import absolute_import, division, print_function, unicode_literals
import tensorflow as tf
import math
import numpy as np
import pandas as pd
import hazm
import nltk
import transformers
from transformers import AutoTokenizer, AutoConfig
from transformers import TFAutoModelForTokenClassification
from BertBasedIntent import IntentClassifier
from CityTranslate import translate
from NER import load_ner_model, NER
from ReligiousAPI import ReligiousAPI
from TimeAPI import TimeAPI
from Utils import date_to_event, event_to_date
from WeatherAPI import WeatherAPI
print()
print('tensorflow', tf.__version__, sep="\t")
print('transformers', transformers.__version__, sep="\t")
print('numpy ', np.__version__, sep="\t")
print('pandas ', pd.__version__, sep="\t")
print()
class BOT():
def __init__(self):
print("Loading Intent model...")
self.intent_model = IntentClassifier().classify
print("Loading NER model...")
if tf.test.gpu_device_name() != '/device:GPU:0':
print('GPU not found, using CPU...')
else:
print('Found GPU: {}'.format(tf.test.gpu_device_name()))
model_name = 'HooshvareLab/bert-base-parsbert-peymaner-uncased'
self.ner_model, self.ner_tokenizer = load_ner_model(model_name)
def AIBOT(self, question):
output = {}
output["type"] = self.intent_model(question)
output = NER(question, self.ner_model, self.ner_tokenizer, mode=output["type"])
output["type"] = str(output["type"])
return output