챗봇

오픈소스 이용:

GitHub - mainadennis/An-AI-Chatbot-in-Python-and-Flask at 6cb96505fc1da684277ef77569d5f2f2e622fcc7

주요 기능: 검색 기능

검색 내용(intents.json)

train.py로 모델 학습 후 app.py로 실행

오픈소스 코드에서 수정사항(app.py)

  1. 파이썬 dictionary로 만들어진 결과를 json로 변환해 반환
dict_string=dict()#딕셔너리 변수 생성
        dict_string['msg']=res#딕셔너리에 value값을 넣음
        json_string = json.dumps(dict_string, ensure_ascii=False)#json으로 변환
        return json_string
  1. Json file load utf-8로 (한글 깨짐 해결)
# 챗봇 초기화
model = load_model("chatbot_model.h5")
with open("intents.json", encoding="utf-8") as f:
    intents = json.load(f)

오픈소스 코드에서 수정사항(train.py)

  1. Json file load utf-8로 (한글 깨짐 해결)
# 파일 load
words = []
classes = []
documents = []
ignore_words = ["?", "!"]
with open("intents.json", encoding="utf-8") as f:
    intents = json.load(f)

흐름

슬라이드1.PNG

Post란 요청 본문에 데이터가 래핑된 요청을 보내는 것. 여기서는 form-data(양식 데이터), 즉 key-value 쌍으로 작성해서 보내는 방식