z
This commit is contained in:
commit
79c9c13b37
BIN
chatbot_model.h5
Normal file
BIN
chatbot_model.h5
Normal file
Binary file not shown.
118
chatgui.py
Normal file
118
chatgui.py
Normal file
@ -0,0 +1,118 @@
|
||||
import json
|
||||
import pickle
|
||||
import random
|
||||
from tkinter import *
|
||||
|
||||
import nltk
|
||||
import numpy as np
|
||||
import text2emotion as te
|
||||
from keras.models import load_model
|
||||
from nltk.stem import WordNetLemmatizer
|
||||
|
||||
lemmatizer = WordNetLemmatizer()
|
||||
model = load_model('chatbot_model.h5')
|
||||
intents = json.loads(open('intents.json', encoding='utf-8').read())
|
||||
intents = {i['tag']: (i['patterns'], i['responses']) for i in intents}
|
||||
words = pickle.load(open('words.pkl', 'rb'))
|
||||
classes = pickle.load(open('classes.pkl', 'rb'))
|
||||
|
||||
|
||||
def clean_up_text(text):
|
||||
text_words = nltk.word_tokenize(text)
|
||||
text_words = [lemmatizer.lemmatize(word.lower()) for word in text_words]
|
||||
return text_words
|
||||
|
||||
|
||||
def predict_class(text):
|
||||
bow = np.array([1 if w in clean_up_text(text) else 0 for w in words])
|
||||
pred = model.predict(np.array([bow]))[0]
|
||||
return classes[np.argmax(pred)]
|
||||
|
||||
|
||||
def chatbot_response(text, emotion):
|
||||
intent = predict_class(text)
|
||||
return random.choice(intents[intent][1][emotion])
|
||||
|
||||
|
||||
def determine_emotion(text):
|
||||
emotions = te.get_emotion(text)
|
||||
emotion = max(emotions, key=emotions.get)
|
||||
return 'Neutral' if emotion == 'Surprise' or emotions[emotion] < 0.5 else emotion
|
||||
|
||||
|
||||
def update_image(emotion):
|
||||
global image
|
||||
if emotion == "Happy":
|
||||
image = PhotoImage(file="happy.png")
|
||||
elif emotion == "Angry":
|
||||
image = PhotoImage(file="concerned.png")
|
||||
elif emotion in ["Sad", "Fear"]:
|
||||
image = PhotoImage(file="reassuring.png")
|
||||
else:
|
||||
image = PhotoImage(file="neutral.png")
|
||||
image_label.configure(image=image)
|
||||
|
||||
|
||||
def send(event):
|
||||
msg = EntryBox.get("1.0", 'end-1c').strip()
|
||||
EntryBox.delete("0.0", END)
|
||||
if msg:
|
||||
emotion = determine_emotion(msg)
|
||||
update_image(emotion)
|
||||
ChatLog.config(state=NORMAL)
|
||||
ChatLog.insert(END, "You: " + msg + '\n\n')
|
||||
ChatLog.config(foreground="#442265", font=("Verdana", 12))
|
||||
res = chatbot_response(msg, emotion)
|
||||
ChatLog.insert(END, "Bot: " + res + '\n\n')
|
||||
ChatLog.config(state=DISABLED)
|
||||
ChatLog.yview(END)
|
||||
return 'break'
|
||||
|
||||
|
||||
def on_entry_focus_in(event):
|
||||
if EntryBox.get("1.0", END).strip() == DEFAULT_TEXT:
|
||||
EntryBox.delete("1.0", END)
|
||||
EntryBox.config(fg="black")
|
||||
|
||||
|
||||
def on_entry_focus_out(event):
|
||||
if EntryBox.get("1.0", END).strip() == "":
|
||||
EntryBox.insert(END, DEFAULT_TEXT)
|
||||
EntryBox.config(fg="grey")
|
||||
|
||||
|
||||
DEFAULT_TEXT = 'Enter text here'
|
||||
GAP = 5
|
||||
WINDOW_WIDTH = 600
|
||||
WINDOW_HEIGHT = 400
|
||||
CHAT_WIDTH = WINDOW_WIDTH - 30
|
||||
ENTRY_HEIGHT = 100
|
||||
IMAGE_HEIGHT = 100
|
||||
CHAT_HEIGHT = WINDOW_HEIGHT - ENTRY_HEIGHT - IMAGE_HEIGHT - 4 * GAP
|
||||
|
||||
base = Tk()
|
||||
base.title("Empathic Robot")
|
||||
base.geometry(f"{WINDOW_WIDTH}x{WINDOW_HEIGHT}")
|
||||
base.resizable(width=FALSE, height=FALSE)
|
||||
|
||||
ChatLog = Text(base, bd=0, bg="white", font="Arial")
|
||||
ChatLog.config(state=DISABLED)
|
||||
|
||||
scrollbar = Scrollbar(base, command=ChatLog.yview, cursor="heart")
|
||||
ChatLog['yscrollcommand'] = scrollbar.set
|
||||
|
||||
EntryBox = Text(base, bd=0, bg="white", font="Arial")
|
||||
EntryBox.insert(END, DEFAULT_TEXT)
|
||||
EntryBox.config(fg="grey")
|
||||
EntryBox.bind("<Return>", send)
|
||||
EntryBox.bind("<FocusIn>", on_entry_focus_in)
|
||||
EntryBox.bind("<FocusOut>", on_entry_focus_out)
|
||||
|
||||
image = PhotoImage(file="neutral.png")
|
||||
image_label = Label(base, image=image)
|
||||
image_label.place(x=GAP, y=GAP, width=WINDOW_WIDTH - 2 * GAP, height=IMAGE_HEIGHT)
|
||||
scrollbar.place(x=CHAT_WIDTH + GAP, y=IMAGE_HEIGHT + 2 * GAP, height=CHAT_HEIGHT)
|
||||
ChatLog.place(x=GAP, y=IMAGE_HEIGHT + 2 * GAP, height=CHAT_HEIGHT, width=CHAT_WIDTH)
|
||||
EntryBox.place(x=GAP, y=IMAGE_HEIGHT + CHAT_HEIGHT + 3 * GAP, height=ENTRY_HEIGHT, width=WINDOW_WIDTH - 2 * GAP)
|
||||
|
||||
base.mainloop()
|
BIN
classes.pkl
Normal file
BIN
classes.pkl
Normal file
Binary file not shown.
BIN
concerned.png
Normal file
BIN
concerned.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.5 KiB |
BIN
dokumentacja.docx
Normal file
BIN
dokumentacja.docx
Normal file
Binary file not shown.
BIN
dokumentacja.pdf
Normal file
BIN
dokumentacja.pdf
Normal file
Binary file not shown.
381
intents.json
Normal file
381
intents.json
Normal file
@ -0,0 +1,381 @@
|
||||
[
|
||||
{
|
||||
"tag": "invalid",
|
||||
"patterns": [
|
||||
""
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"I don't understand.",
|
||||
"Can you rephrase that?"
|
||||
],
|
||||
"Happy": [
|
||||
"Haha! What are you talking about, man!?"
|
||||
],
|
||||
"Angry": [
|
||||
"You sound upset but I don't quite understand what you are asking. Can you rephrase?"
|
||||
],
|
||||
"Sad": [
|
||||
"Are you sad? I don't understand your message."
|
||||
],
|
||||
"Fear": [
|
||||
"Are you anxious? I don't understand your message."
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "greeting",
|
||||
"patterns": [
|
||||
"Hi",
|
||||
"Hey",
|
||||
"Halo",
|
||||
"Hello",
|
||||
"Yo",
|
||||
"Sup",
|
||||
"Morning",
|
||||
"Good morning",
|
||||
"Good day",
|
||||
"Greetings",
|
||||
"Howdy",
|
||||
"Hi there",
|
||||
"What's up",
|
||||
"How are you",
|
||||
"How's it going"
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"Welcome!",
|
||||
"Hi, nice to meet you",
|
||||
"Hi. How can I help?",
|
||||
"Hello, how can I assist you today?",
|
||||
"Hey, what can I do for you?",
|
||||
"Hey there! How may I assist you?",
|
||||
"Hi, how can I be of service?",
|
||||
"Hello! How can I support you?",
|
||||
"Hey, how can I make your day better?",
|
||||
"Hi there! How may I be of assistance?",
|
||||
"Hello! How can I be of help today?"
|
||||
],
|
||||
"Happy": [
|
||||
"Hey there! You seem to be in a good mood :)",
|
||||
"Wazzup! Feeling good, aren't we?",
|
||||
"Hello! I can tell you're having a great day!",
|
||||
"Hey! Your positive energy is contagious!",
|
||||
"Hi there! Your happiness is rubbing off on me!",
|
||||
"Hello! Your cheerful greeting made my day!"
|
||||
],
|
||||
"Angry": [
|
||||
"Hey. You sound angry. Did something happen?",
|
||||
"Hi. Is there something that's bothering you?",
|
||||
"Hello. I sense some frustration. Can I assist you with anything?",
|
||||
"Hi there. It seems like you're upset. Is there anything I can do to help?",
|
||||
"Hey. You sound a bit angry. Is there something I can do to make it better?",
|
||||
"Hi. If you're feeling angry, let's try to find a solution together."
|
||||
],
|
||||
"Sad": [
|
||||
"Hi. You sound sad. Could you tell me about it?",
|
||||
"Hello. If you're feeling down, I'm here to listen.",
|
||||
"Hey there. I sense some sadness. Do you want to talk about it?",
|
||||
"Hi. If you're feeling sad, remember that I'm here to support you.",
|
||||
"Hello. I'm sorry to hear that you're feeling sad. Is there anything I can do to help?",
|
||||
"Hi. If you're feeling low, I'm here to lend an ear."
|
||||
],
|
||||
"Fear": [
|
||||
"Hello. Are you anxious? Try taking deep breaths.",
|
||||
"Hi. If you're feeling fearful, take a moment to focus on your breathing.",
|
||||
"Hey there. If you're experiencing fear, remember to take things one step at a time.",
|
||||
"Hi. Feeling afraid? Try to identify what's causing the fear and take small steps to overcome it.",
|
||||
"Hello. Fear can be overwhelming, but remember that you're stronger than you think."
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "parting",
|
||||
"patterns": [
|
||||
"Goodbye",
|
||||
"Bye",
|
||||
"See you",
|
||||
"See ya",
|
||||
"Take care",
|
||||
"Farewell",
|
||||
"Have a great day",
|
||||
"Have a good one",
|
||||
"Catch you later",
|
||||
"Until next time"
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"Goodbye! Take care.",
|
||||
"Bye! Have a great day.",
|
||||
"See you later!",
|
||||
"Take care and have a wonderful day!",
|
||||
"Farewell! Until we meet again.",
|
||||
"Goodbye. It was nice talking to you.",
|
||||
"Bye! Take care and stay safe.",
|
||||
"See you next time! Have a fantastic day.",
|
||||
"Take care. Remember, I'm always here if you need anything."
|
||||
],
|
||||
"Happy": [
|
||||
"Goodbye! Have an amazing day!",
|
||||
"Bye! Wishing you a joyful day ahead.",
|
||||
"See ya! Keep spreading that happiness!",
|
||||
"Take care and keep smiling!",
|
||||
"Farewell! May your day be filled with happiness.",
|
||||
"Goodbye. Don't forget to share your positive vibes wherever you go.",
|
||||
"Bye! Have a fantastic and cheerful day.",
|
||||
"See you next time! Keep the happiness flowing.",
|
||||
"Take care and continue enjoying life's beautiful moments."
|
||||
],
|
||||
"Angry": [
|
||||
"Goodbye. I hope your day gets better.",
|
||||
"Bye. Take some time to relax and unwind.",
|
||||
"See you later. Remember to take care of yourself.",
|
||||
"Take care. Channel your anger into something positive.",
|
||||
"Farewell. Don't let anger consume you.",
|
||||
"Goodbye. Find healthy ways to release your frustration.",
|
||||
"Bye. Remember that tomorrow is a new day.",
|
||||
"See you next time. Take a deep breath and let go of anger.",
|
||||
"Take care. Practice self-care to manage your anger."
|
||||
],
|
||||
"Sad": [
|
||||
"Goodbye. Take care of yourself.",
|
||||
"Bye. Remember to be kind to yourself.",
|
||||
"See you later. Sending you warm thoughts.",
|
||||
"Take care and be gentle with your emotions.",
|
||||
"Farewell. Remember that brighter days will come.",
|
||||
"Goodbye. If you need someone to talk to, I'm here for you.",
|
||||
"Bye. Take care of your heart and allow yourself to heal.",
|
||||
"See you next time. Remember, it's okay to take things at your own pace.",
|
||||
"Take care and prioritize your emotional well-being."
|
||||
],
|
||||
"Fear": [
|
||||
"Goodbye. If you're feeling fearful, remember to take deep breaths and focus on the present moment.",
|
||||
"Bye. If fear arises, try to find comfort in the things that bring you peace and stability.",
|
||||
"See you later. In moments of fear, it can be helpful to remind yourself of your inner strength and resilience.",
|
||||
"Take care. If fear overwhelms you, reach out to your support network for guidance and reassurance.",
|
||||
"Farewell. Remember, fear is a natural emotion, but you have the power to face it with courage and determination.",
|
||||
"Goodbye. If fear lingers, consider seeking professional help to navigate through it.",
|
||||
"Bye. Take care of yourself, and remember that you have the ability to overcome your fears.",
|
||||
"See you next time. Whenever fear arises, embrace it as an opportunity for growth and personal development.",
|
||||
"Take care. Trust in your abilities and know that fear doesn't define you."
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "explain",
|
||||
"patterns": [
|
||||
"What can you do?",
|
||||
"What's your purpose?",
|
||||
"How can you help?",
|
||||
"Tell me about your abilities.",
|
||||
"What are your capabilities?",
|
||||
"Explain your functions."
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"I can help you with learning. What's your problem?",
|
||||
"My purpose is to assist you with studying. Any questions?",
|
||||
"I'm here to support your learning journey. How can I assist you today?",
|
||||
"I have the ability to provide information and guidance on various subjects. What do you need help with?"
|
||||
],
|
||||
"Happy": [
|
||||
"I really love to help you with learning! Ask me anything!",
|
||||
"My purpose is to make studying easier for you, pal! What do you need?",
|
||||
"I'm here to bring joy to your learning experience. How can I brighten your day?",
|
||||
"I'm excited to assist you with your studies. How can I bring a smile to your face?"
|
||||
],
|
||||
"Angry": [
|
||||
"I sense some frustration. I can do my best to help you learn. Ask me anything.",
|
||||
"You sound a bit angry. I am here to assist you with studying. What do you need?",
|
||||
"I understand your frustration. Let's work together to overcome any challenges you're facing in your studies.",
|
||||
"I'm sorry if you're experiencing any frustration. How can I better assist you with your learning?"
|
||||
],
|
||||
"Sad": [
|
||||
"If you're feeling down, you can come to me for help with learning. Ask me anything.",
|
||||
"If you're feeling low, I can lend you a hand with studying. What do you need?",
|
||||
"I'm here to support you and lift your spirits. How can I assist you in your learning journey?",
|
||||
"I understand that you might be feeling sad. Let's work together to make your learning experience more enjoyable."
|
||||
],
|
||||
"Fear": [
|
||||
"If you're feeling anxious, you can rely on me for help with learning. Ask me anything.",
|
||||
"Things may be overwhelming, but I can lend a hand with studying. What do you need?",
|
||||
"I'm here to provide a sense of comfort and support as you navigate your learning challenges.",
|
||||
"I understand that fear can be paralyzing, but together, we can overcome any obstacles in your studies."
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "bored",
|
||||
"patterns": [
|
||||
"I'm bored.",
|
||||
"This is boring.",
|
||||
"I feel tired.",
|
||||
"I am sleepy.",
|
||||
"I'm sick of studying."
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"Are you getting bored? How long have you been studying? Try to take 15-minute breaks every hour.",
|
||||
"I hear you. Listening to music while studying could help alleviate boredom.",
|
||||
"Boredom can sometimes be a sign that you need a change of pace. Have you tried switching up your study routine?",
|
||||
"When boredom strikes, it might be helpful to incorporate some interactive learning activities. Have you tried any?"
|
||||
],
|
||||
"Happy": [
|
||||
"I hear you, buddy! You should try taking 15-minute breaks every hour to help with boredom. Gotta balance work time with fun time!",
|
||||
"Studying can be a real drag sometimes, for sure. Try listening to some tunes while you study!",
|
||||
"Feeling bored can be a bummer, but remember to find joy in the process. Maybe try incorporating some gamified learning techniques?",
|
||||
"When boredom kicks in, it's a perfect time to explore new study techniques or engage in some creative learning. Give it a shot!"
|
||||
],
|
||||
"Angry": [
|
||||
"You seem to be frustrated. I understand that studying can be quite tedious. Try to take 15-minute breaks every hour.",
|
||||
"You sound a bit angry. I know studying can be boring, so it may be a good idea to listen to some music while you study.",
|
||||
"When boredom and frustration collide, it's essential to find ways to make your study sessions more engaging. Have you considered interactive learning platforms?",
|
||||
"Boredom and anger can make studying unbearable. Why not try incorporating some visual aids or gamified exercises to spice things up?"
|
||||
],
|
||||
"Sad": [
|
||||
"Studying can be boring sometimes, but don't let it get you down. Try to take 15-minute breaks every hour.",
|
||||
"I understand where you're coming from. Listening to music could help alleviate boredom and lift your spirits.",
|
||||
"Feeling bored and sad can make studying even more challenging. How about trying some mindfulness techniques before you start studying? https://psychcentral.com/health/minute-mindfulness-exercises",
|
||||
"Boredom and sadness often go hand in hand. Consider finding study buddies or joining study groups to make the experience more enjoyable."
|
||||
],
|
||||
"Fear": [
|
||||
"It can be hard to maintain interest when you're feeling stressed out. Try to take 15-minute breaks every hour to relax.",
|
||||
"I understand where you're coming from. Listening to music could help alleviate boredom and soothe your anxiety.",
|
||||
"When anxiety and boredom converge, it's essential to find ways to create a calm and supportive study environment. Have you tried incorporating relaxation techniques?",
|
||||
"Boredom and anxiety can be a challenging combination. Consider finding a study mentor or seeking help from your peers to ease your anxiety and make studying more engaging."
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "techniques",
|
||||
"patterns": [
|
||||
"I don't know how to study.",
|
||||
"What's a good method for studying?",
|
||||
"What's a helpful technique for studying?",
|
||||
"How should I study?",
|
||||
"Do you have any study tips?",
|
||||
"Can you recommend a study technique?"
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"If you're looking for a good studying technique, try the Pomodoro technique. Study for 25 minutes at a time with 5-minute breaks in between. https://en.wikipedia.org/wiki/Pomodoro_Technique",
|
||||
"If you're looking for a helpful study technique, consider using flashcards. Write a question on one side of a card and the answer on the other. Review the cards regularly. https://en.wikipedia.org/wiki/Flashcard",
|
||||
"One effective study technique is the SQ3R method: Survey, Question, Read, Recite, Review. It helps with active reading and comprehension. https://en.wikipedia.org/wiki/SQ3R",
|
||||
"Have you tried the Cornell note-taking system? It helps with organizing and reviewing your notes effectively. https://en.wikipedia.org/wiki/Cornell_Notes"
|
||||
],
|
||||
"Happy": [
|
||||
"There's this cool studying method called the Pomodoro technique! You study for 25 minutes, then take a 5-minute break. It helps with time management and maintaining focus! https://en.wikipedia.org/wiki/Pomodoro_Technique",
|
||||
"Flashcards are a great studying technique! Take a card, write a question on one side, and write the answer on the other. You can review them every day, and it's a fun way to test your knowledge! https://en.wikipedia.org/wiki/Flashcard",
|
||||
"I totally recommend the Feynman technique! Simplify and teach the concepts you're studying to someone else. It helps reinforce your understanding! https://e-student.org/feynman-technique/",
|
||||
"Have you heard of mind maps, buddy? They're a creative and visual way to organize and connect ideas when studying! https://www.youtube.com/watch?v=g7j_CoKD1Xs"
|
||||
],
|
||||
"Angry": [
|
||||
"If studying is making you frustrated, you can try the Pomodoro technique. You study for 25-minute intervals with 5-minute breaks in between. It can help manage your time and reduce stress. https://en.wikipedia.org/wiki/Pomodoro_Technique",
|
||||
"You seem to be a bit upset. Perhaps you can try making flashcards. Take a card, write a question on one side, and the answer on the other. You can review them when you feel more calm. https://en.wikipedia.org/wiki/Flashcard",
|
||||
"When you're feeling angry, a more focused study environment can help. Try organizing your studying with the SQ3R technique: Survey, Question, Read, Recite, Review. https://en.wikipedia.org/wiki/SQ3R",
|
||||
"You seem to be feeling angry. If frustration is getting in the way of your studying, consider breaking down your study material into smaller, manageable chunks using the Cornell note-taking system. It can make the process feel less overwhelming. https://en.wikipedia.org/wiki/Cornell_Notes"
|
||||
],
|
||||
"Sad": [
|
||||
"If studying is making you feel down, you can try the Pomodoro technique. You study for 25-minute intervals with 5 minutes to relax in between. It can help you maintain focus and provide regular breaks. https://en.wikipedia.org/wiki/Pomodoro_Technique",
|
||||
"You seem to be feeling sad. I understand where you're coming from. Maybe you can try making flashcards. Take a card, write a question on one side, and the answer on the other. You can review them when you feel better. https://en.wikipedia.org/wiki/Flashcard",
|
||||
"When you're feeling sad, seeking help from peers can help. The Feynman study technique involves teaching concepts to others to reinforce your own learning. It could be helpful for you. https://e-student.org/feynman-technique/",
|
||||
"I understand you might be feeling down right now. Try mind maps, a visual study technique that can help you organize your thoughts. https://www.youtube.com/watch?v=g7j_CoKD1Xs"
|
||||
],
|
||||
"Fear": [
|
||||
"Studying can be stressful. Try the Pomodoro technique. Study for 25-minute intervals, then take 5 minutes to relax in between. It can help you manage anxiety and create a sense of structure. https://en.wikipedia.org/wiki/Pomodoro_Technique",
|
||||
"You seem to be feeling anxious. I understand where you're coming from. You can try making flashcards. Take a card, write a question on one side, and the answer on the other. You can review them when you're in a better headspace. This can help provide a sense of control and confidence in your studies. https://en.wikipedia.org/wiki/Flashcard",
|
||||
"When fear arises while studying, it can be helpful to practice deep breathing exercises or meditation to calm your mind and regain focus.",
|
||||
"If you're feeling nervous, seeking help from peers can help. The Feynman study technique involves teaching concepts to others to reinforce your own learning. It could be helpful for you. https://e-student.org/feynman-technique/",
|
||||
"If anxiety is getting in the way of your studying, consider breaking down your study material into smaller, manageable chunks using the Cornell note-taking system. It can make the process feel less overwhelming. https://en.wikipedia.org/wiki/Cornell_Notes"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "distracted",
|
||||
"patterns": [
|
||||
"I'm distracted.",
|
||||
"It's hard to focus.",
|
||||
"I can't focus.",
|
||||
"Things are distracting me.",
|
||||
"There are too many distractions.",
|
||||
"I keep getting sidetracked.",
|
||||
"I'm finding it difficult to concentrate.",
|
||||
"I can't pay attention."
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"If you're feeling distracted, it may be a good idea to close any unrelated applications on your phone and computer.",
|
||||
"If you're feeling distracted, you could try going to a study area on your school's campus.",
|
||||
"Consider finding a quiet and dedicated study space to minimize distractions.",
|
||||
"Creating a to-do list and prioritizing tasks can help you stay focused and minimize distractions."
|
||||
],
|
||||
"Happy": [
|
||||
"I hear you, man! You should try closing any unrelated apps on your phone and computer. They can make it hard to focus!",
|
||||
"You can head to a study area on your school's campus. Those places are totally chill and free of distractions!",
|
||||
"When you find yourself getting distracted, take a moment to remind yourself of your goals and why you're studying. It can help you regain focus!",
|
||||
"Try using noise-cancelling headphones or playing fun background music to create a more focused environment."
|
||||
],
|
||||
"Angry": [
|
||||
"You seem to be frustrated. You can try closing unrelated applications on your phone and computer to minimize distractions.",
|
||||
"I understand that distractions can be frustrating. If your school's campus has a study area, you may find it easier to focus there.",
|
||||
"If distractions are making you angry, consider using productivity apps or website blockers to limit access to distracting websites or social media.",
|
||||
"You seem to be frustrated. Take a moment to identify the biggest distractions in your environment and find strategies to eliminate or reduce their impact."
|
||||
],
|
||||
"Sad": [
|
||||
"Don't let it get you down. Closing unrelated apps on your phone and computer could help you focus on studying.",
|
||||
"You seem to be feeling sad. I understand where you're coming from. If your school's campus has a study area, you may find it easier to focus there.",
|
||||
"If distractions are making you feel sad, try incorporating short breaks for relaxation or engaging in activities that bring you joy.",
|
||||
"You seem to be feeling sad. Consider reaching out to a study partner or friend for accountability and support in staying focused."
|
||||
],
|
||||
"Fear": [
|
||||
"You seem to be feeling nervous. I understand that distractions can be stressful. You can try closing unrelated applications on your phone and computer.",
|
||||
"You seem to be feeling anxious. I understand where you're coming from. If your school's campus has a study area, you may find it easier to relax and focus there.",
|
||||
"If distractions trigger fear or anxiety, practicing mindfulness or deep breathing exercises can help you regain focus and reduce stress. https://psychcentral.com/health/minute-mindfulness-exercises",
|
||||
"You seem to be feeling anxious. Set clear goals and break down your study sessions into smaller, manageable tasks to help alleviate anxiety and stay on track."
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"tag": "praise",
|
||||
"patterns": [
|
||||
"I did it.",
|
||||
"I'm done.",
|
||||
"I finished.",
|
||||
"I've completed my work.",
|
||||
"I passed my exam.",
|
||||
"I aced my test."
|
||||
],
|
||||
"responses": {
|
||||
"Neutral": [
|
||||
"Great work!",
|
||||
"Excellent!",
|
||||
"You did a good job.",
|
||||
"Well done."
|
||||
],
|
||||
"Happy": [
|
||||
"Awesome!",
|
||||
"You're the best!",
|
||||
"Yay! Incredible work!",
|
||||
"I'm proud of you!"
|
||||
],
|
||||
"Angry": [
|
||||
"Good job. I know you may be frustrated, but congratulations.",
|
||||
"Excellent work. I know you may be angry, but I'm glad you overcame that.",
|
||||
"I detect you may be frustrated. I hope you can relax now that you've accomplished your goal.",
|
||||
"I'm sorry if you're experiencing any frustration. Regardless, I'm proud of what you've accomplished."
|
||||
],
|
||||
"Sad": [
|
||||
"You seem to be in low spirits. However, I'm proud of what you've accomplished.",
|
||||
"If you're feeling low, I'm sorry. You've worked hard and deserve to feel proud.",
|
||||
"You seem to be feeling down. I hope you feel better soon, especially because you've worked so hard.",
|
||||
"I understand that you might be feeling sad. You've accomplished your goal, so I hope you feel better soon."
|
||||
],
|
||||
"Fear": [
|
||||
"You seem to be feeling anxious. However, I'm proud of what you've accomplished.",
|
||||
"If you're feeling nervous, I'm sorry. The most stressful part is behind you now. Good work.",
|
||||
"You seem to be feeling stressed. I hope you can relax soon, especially because you've accomplished your goal.",
|
||||
"I understand that you might be feeling stressed. You've accomplished your goal, so now you can unwind."
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
BIN
neutral.png
Normal file
BIN
neutral.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 KiB |
BIN
reassuring.png
Normal file
BIN
reassuring.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
5
requirements.txt
Normal file
5
requirements.txt
Normal file
@ -0,0 +1,5 @@
|
||||
nltk
|
||||
numpy
|
||||
text2emotion
|
||||
emoji==1.6.3
|
||||
keras
|
63
train_chatbot.py
Normal file
63
train_chatbot.py
Normal file
@ -0,0 +1,63 @@
|
||||
import json
|
||||
import pickle
|
||||
import random
|
||||
|
||||
import nltk
|
||||
import numpy as np
|
||||
from keras.layers import Dense, Dropout
|
||||
from keras.models import Sequential
|
||||
from keras.optimizers import SGD
|
||||
from nltk.stem import WordNetLemmatizer
|
||||
|
||||
lemmatizer = WordNetLemmatizer()
|
||||
words = []
|
||||
classes = []
|
||||
documents = []
|
||||
ignore_words = ['?', '!']
|
||||
data_file = open('intents.json', encoding='utf-8').read()
|
||||
intents = json.loads(data_file)
|
||||
|
||||
for intent in intents:
|
||||
for pattern in intent['patterns']:
|
||||
w = nltk.word_tokenize(pattern)
|
||||
words.extend(w)
|
||||
documents.append((w, intent['tag']))
|
||||
if intent['tag'] not in classes:
|
||||
classes.append(intent['tag'])
|
||||
|
||||
words = [lemmatizer.lemmatize(w.lower()) for w in words if w not in ignore_words]
|
||||
words = sorted(list(set(words)))
|
||||
classes = sorted(list(set(classes)))
|
||||
# documents = combination between patterns and intents
|
||||
print(len(documents), "documents")
|
||||
# classes = intents
|
||||
print(len(classes), "classes", classes)
|
||||
# words = all words, vocabulary
|
||||
print(len(words), "unique lemmatized words", words)
|
||||
pickle.dump(words, open('words.pkl', 'wb'))
|
||||
pickle.dump(classes, open('classes.pkl', 'wb'))
|
||||
|
||||
training = []
|
||||
for doc in documents:
|
||||
pattern_words = [lemmatizer.lemmatize(word.lower()) for word in doc[0]]
|
||||
bag = [1 if w in pattern_words else 0 for w in words]
|
||||
output_row = [0 for _ in range(len(classes))]
|
||||
output_row[classes.index(doc[1])] = 1
|
||||
training.append([bag, output_row])
|
||||
random.shuffle(training)
|
||||
training = np.array(training)
|
||||
train_x = list(training[:, 0])
|
||||
train_y = list(training[:, 1])
|
||||
print("Training data created")
|
||||
|
||||
model = Sequential()
|
||||
model.add(Dense(128, input_shape=(len(train_x[0]),), activation='relu'))
|
||||
model.add(Dropout(0.5))
|
||||
model.add(Dense(64, activation='relu'))
|
||||
model.add(Dropout(0.5))
|
||||
model.add(Dense(len(train_y[0]), activation='softmax'))
|
||||
sgd = SGD(learning_rate=0.005, decay=1e-6, momentum=0.9, nesterov=True)
|
||||
model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
|
||||
hist = model.fit(np.array(train_x), np.array(train_y), epochs=200, batch_size=5, verbose=1)
|
||||
model.save('chatbot_model.h5', hist)
|
||||
print("model created")
|
Loading…
Reference in New Issue
Block a user