Spaces:
Sleeping
Sleeping
Commit
·
f3287af
1
Parent(s):
9ec6ed2
update
Browse files- app.py +25 -4
- chatbot +7 -0
- chatbot.pub +1 -0
- data/createcsv.py +83 -0
- data/intents.csv +32 -0
- models/lms_chatbot.joblib +3 -0
- models/responses.joblib +3 -0
- requirements.txt +6 -0
- src/__pycache__/features.cpython-313.pyc +0 -0
- src/__pycache__/predict.cpython-313.pyc +0 -0
- src/__pycache__/preprocess.cpython-313.pyc +0 -0
- src/features.py +11 -0
- src/gui.py +82 -0
- src/predict.py +12 -0
- src/preprocess.py +9 -0
- src/train.py +43 -0
- ssh +7 -0
- ssh.pub +1 -0
app.py
CHANGED
|
@@ -1,7 +1,28 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
from preprocess import clean_text
|
| 4 |
|
| 5 |
+
# Load trained model and responses
|
| 6 |
+
model = joblib.load("models/lms_chatbot.joblib")
|
| 7 |
+
responses = joblib.load("models/responses.joblib")
|
| 8 |
|
| 9 |
+
def chatbot_response(user_input):
|
| 10 |
+
"""Predict the tag and return the corresponding response."""
|
| 11 |
+
clean_input = clean_text(user_input)
|
| 12 |
+
tag = model.predict([clean_input])[0]
|
| 13 |
+
return responses.get(tag, ["Sorry, I don't understand."])[0]
|
| 14 |
+
|
| 15 |
+
def chat_interface(user_input):
|
| 16 |
+
return chatbot_response(user_input)
|
| 17 |
+
|
| 18 |
+
# Gradio Interface
|
| 19 |
+
demo = gr.Interface(
|
| 20 |
+
fn=chat_interface,
|
| 21 |
+
inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
|
| 22 |
+
outputs="text",
|
| 23 |
+
title="LMS Chatbot",
|
| 24 |
+
description="Ask anything about LMS and get automated responses."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
demo.launch()
|
chatbot
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN OPENSSH PRIVATE KEY-----
|
| 2 |
+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
|
| 3 |
+
QyNTUxOQAAACAwnOVBd+a3fINwdYA09Am0riox/ADpztA5vZJdVKFLPgAAAKBUZqnRVGap
|
| 4 |
+
0QAAAAtzc2gtZWQyNTUxOQAAACAwnOVBd+a3fINwdYA09Am0riox/ADpztA5vZJdVKFLPg
|
| 5 |
+
AAAEByNpoQkGuaG3/+yt9+W0vEZPWNAH1W7sKU1lI9v131cDCc5UF35rd8g3B1gDT0CbSu
|
| 6 |
+
KjH8AOnO0Dm9kl1UoUs+AAAAFnlvdXJfZW1haWxAZXhhbXBsZS5jb20BAgMEBQYH
|
| 7 |
+
-----END OPENSSH PRIVATE KEY-----
|
chatbot.pub
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDCc5UF35rd8g3B1gDT0CbSuKjH8AOnO0Dm9kl1UoUs+ your_email@example.com
|
data/createcsv.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
DATA = {
|
| 5 |
+
"greeting": {
|
| 6 |
+
"patterns": ["Hello", "Hi there", "Hey", "Good morning", "Good evening"],
|
| 7 |
+
"responses": ["Hello! How can I help you today?", "Hi! What would you like to know about your LMS?"]
|
| 8 |
+
},
|
| 9 |
+
"goodbye": {
|
| 10 |
+
"patterns": ["Goodbye", "Bye", "See you", "Catch you later"],
|
| 11 |
+
"responses": ["Goodbye! Have a great day.", "See you soon!"]
|
| 12 |
+
},
|
| 13 |
+
"courses": {
|
| 14 |
+
"patterns": ["What courses am I enrolled in?", "List all my courses", "How many credits do I have?"],
|
| 15 |
+
"responses": [
|
| 16 |
+
"You are enrolled in several courses. Please check your LMS dashboard.",
|
| 17 |
+
"Here is the list of your enrolled courses in the LMS.",
|
| 18 |
+
"You can view your total credits in your academic profile."
|
| 19 |
+
]
|
| 20 |
+
},
|
| 21 |
+
"grades": {
|
| 22 |
+
"patterns": ["Show my grades", "How do I view my grades?", "Check my performance"],
|
| 23 |
+
"responses": [
|
| 24 |
+
"Your grades are available in the 'Grades' section of the LMS.",
|
| 25 |
+
"Go to the 'Grades' tab in the LMS to check your performance."
|
| 26 |
+
]
|
| 27 |
+
},
|
| 28 |
+
"assignment": {
|
| 29 |
+
"patterns": ["When is the assignment due?", "How do I submit my homework?", "Upload assignment"],
|
| 30 |
+
"responses": [
|
| 31 |
+
"You can check assignment deadlines in the 'Assignments' section.",
|
| 32 |
+
"Upload your homework in the LMS under 'Assignments'."
|
| 33 |
+
]
|
| 34 |
+
},
|
| 35 |
+
"schedule": {
|
| 36 |
+
"patterns": ["List all upcoming lectures", "What is the next lecture topic?", "Show timetable"],
|
| 37 |
+
"responses": [
|
| 38 |
+
"Upcoming lectures are listed in your calendar on the LMS.",
|
| 39 |
+
"The next lecture topic is available in the course schedule."
|
| 40 |
+
]
|
| 41 |
+
},
|
| 42 |
+
"instructor": {
|
| 43 |
+
"patterns": ["Who is my instructor?", "Who teaches this course?"],
|
| 44 |
+
"responses": ["You can find your instructor details on the course information page."]
|
| 45 |
+
},
|
| 46 |
+
"technical_support": {
|
| 47 |
+
"patterns": ["How can I reset my password?", "My portal is not loading", "LMS not working"],
|
| 48 |
+
"responses": [
|
| 49 |
+
"Go to account settings and click on 'Reset Password'.",
|
| 50 |
+
"Try clearing your cache or contact IT support."
|
| 51 |
+
]
|
| 52 |
+
},
|
| 53 |
+
"feedback": {
|
| 54 |
+
"patterns": ["How do I give feedback?", "I want to share my opinion"],
|
| 55 |
+
"responses": ["You can provide feedback through the LMS feedback form."]
|
| 56 |
+
},
|
| 57 |
+
"resources": {
|
| 58 |
+
"patterns": ["Where can I find course materials?", "How can I access lecture notes?", "Show learning materials"],
|
| 59 |
+
"responses": [
|
| 60 |
+
"Course materials are available under the 'Resources' section.",
|
| 61 |
+
"Lecture notes are uploaded in the course resources."
|
| 62 |
+
]
|
| 63 |
+
}
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
# Convert into rows for DataFrame (expand patterns into rows)
|
| 67 |
+
rows = []
|
| 68 |
+
for intent, data in DATA.items():
|
| 69 |
+
for pattern in data["patterns"]: # one row per pattern
|
| 70 |
+
rows.append({
|
| 71 |
+
"tag": intent, # <-- renamed to tag
|
| 72 |
+
"patterns": pattern,
|
| 73 |
+
"responses": ";".join(data["responses"]) # keep multiple responses joined
|
| 74 |
+
})
|
| 75 |
+
|
| 76 |
+
df = pd.DataFrame(rows, columns=["tag", "patterns", "responses"])
|
| 77 |
+
|
| 78 |
+
# Save CSV inside data/ folder
|
| 79 |
+
OUT = Path(__file__).resolve().parent.parent / "data" / "intents.csv"
|
| 80 |
+
OUT.parent.mkdir(parents=True, exist_ok=True)
|
| 81 |
+
df.to_csv(OUT, index=False, encoding="utf-8")
|
| 82 |
+
|
| 83 |
+
print(f"✅ Created intents CSV at {OUT}")
|
data/intents.csv
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tag,patterns,responses
|
| 2 |
+
greeting,Hello,Hello! How can I help you today?;Hi! What would you like to know about your LMS?
|
| 3 |
+
greeting,Hi there,Hello! How can I help you today?;Hi! What would you like to know about your LMS?
|
| 4 |
+
greeting,Hey,Hello! How can I help you today?;Hi! What would you like to know about your LMS?
|
| 5 |
+
greeting,Good morning,Hello! How can I help you today?;Hi! What would you like to know about your LMS?
|
| 6 |
+
greeting,Good evening,Hello! How can I help you today?;Hi! What would you like to know about your LMS?
|
| 7 |
+
goodbye,Goodbye,Goodbye! Have a great day.;See you soon!
|
| 8 |
+
goodbye,Bye,Goodbye! Have a great day.;See you soon!
|
| 9 |
+
goodbye,See you,Goodbye! Have a great day.;See you soon!
|
| 10 |
+
goodbye,Catch you later,Goodbye! Have a great day.;See you soon!
|
| 11 |
+
courses,What courses am I enrolled in?,You are enrolled in several courses. Please check your LMS dashboard.;Here is the list of your enrolled courses in the LMS.;You can view your total credits in your academic profile.
|
| 12 |
+
courses,List all my courses,You are enrolled in several courses. Please check your LMS dashboard.;Here is the list of your enrolled courses in the LMS.;You can view your total credits in your academic profile.
|
| 13 |
+
courses,How many credits do I have?,You are enrolled in several courses. Please check your LMS dashboard.;Here is the list of your enrolled courses in the LMS.;You can view your total credits in your academic profile.
|
| 14 |
+
grades,Show my grades,Your grades are available in the 'Grades' section of the LMS.;Go to the 'Grades' tab in the LMS to check your performance.
|
| 15 |
+
grades,How do I view my grades?,Your grades are available in the 'Grades' section of the LMS.;Go to the 'Grades' tab in the LMS to check your performance.
|
| 16 |
+
grades,Check my performance,Your grades are available in the 'Grades' section of the LMS.;Go to the 'Grades' tab in the LMS to check your performance.
|
| 17 |
+
assignment,When is the assignment due?,You can check assignment deadlines in the 'Assignments' section.;Upload your homework in the LMS under 'Assignments'.
|
| 18 |
+
assignment,How do I submit my homework?,You can check assignment deadlines in the 'Assignments' section.;Upload your homework in the LMS under 'Assignments'.
|
| 19 |
+
assignment,Upload assignment,You can check assignment deadlines in the 'Assignments' section.;Upload your homework in the LMS under 'Assignments'.
|
| 20 |
+
schedule,List all upcoming lectures,Upcoming lectures are listed in your calendar on the LMS.;The next lecture topic is available in the course schedule.
|
| 21 |
+
schedule,What is the next lecture topic?,Upcoming lectures are listed in your calendar on the LMS.;The next lecture topic is available in the course schedule.
|
| 22 |
+
schedule,Show timetable,Upcoming lectures are listed in your calendar on the LMS.;The next lecture topic is available in the course schedule.
|
| 23 |
+
instructor,Who is my instructor?,You can find your instructor details on the course information page.
|
| 24 |
+
instructor,Who teaches this course?,You can find your instructor details on the course information page.
|
| 25 |
+
technical_support,How can I reset my password?,Go to account settings and click on 'Reset Password'.;Try clearing your cache or contact IT support.
|
| 26 |
+
technical_support,My portal is not loading,Go to account settings and click on 'Reset Password'.;Try clearing your cache or contact IT support.
|
| 27 |
+
technical_support,LMS not working,Go to account settings and click on 'Reset Password'.;Try clearing your cache or contact IT support.
|
| 28 |
+
feedback,How do I give feedback?,You can provide feedback through the LMS feedback form.
|
| 29 |
+
feedback,I want to share my opinion,You can provide feedback through the LMS feedback form.
|
| 30 |
+
resources,Where can I find course materials?,Course materials are available under the 'Resources' section.;Lecture notes are uploaded in the course resources.
|
| 31 |
+
resources,How can I access lecture notes?,Course materials are available under the 'Resources' section.;Lecture notes are uploaded in the course resources.
|
| 32 |
+
resources,Show learning materials,Course materials are available under the 'Resources' section.;Lecture notes are uploaded in the course resources.
|
models/lms_chatbot.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e5b09fc9fcc603129da2794a579456133e64038e1316f330f76713bd04f280ed
|
| 3 |
+
size 11745
|
models/responses.joblib
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1094bb45c27e767c181ebc2e624768568e1dc16b5066ab71303663cee89f3371
|
| 3 |
+
size 1241
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
scikit-learn
|
| 3 |
+
nltk
|
| 4 |
+
joblib
|
| 5 |
+
ttkbootstrap
|
| 6 |
+
|
src/__pycache__/features.cpython-313.pyc
ADDED
|
Binary file (706 Bytes). View file
|
|
|
src/__pycache__/predict.cpython-313.pyc
ADDED
|
Binary file (876 Bytes). View file
|
|
|
src/__pycache__/preprocess.cpython-313.pyc
ADDED
|
Binary file (690 Bytes). View file
|
|
|
src/features.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 2 |
+
from sklearn.pipeline import Pipeline
|
| 3 |
+
from sklearn.linear_model import LogisticRegression
|
| 4 |
+
|
| 5 |
+
def build_pipeline(random_state=42):
|
| 6 |
+
vect = TfidfVectorizer(max_df=0.9, min_df=1, ngram_range=(1,2))
|
| 7 |
+
clf = LogisticRegression(max_iter=1000, random_state=random_state)
|
| 8 |
+
return Pipeline([
|
| 9 |
+
("tfidf", vect),
|
| 10 |
+
("clf", clf)
|
| 11 |
+
])
|
src/gui.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tkinter as tk
|
| 2 |
+
from tkinter import Canvas, Frame, Scrollbar, Label, Entry, BOTH, RIGHT, LEFT, Y, NW
|
| 3 |
+
from predict import chatbot_response
|
| 4 |
+
|
| 5 |
+
class ChatbotGUI:
|
| 6 |
+
def __init__(self, root):
|
| 7 |
+
self.root = root
|
| 8 |
+
self.root.title("LMS Chatbot")
|
| 9 |
+
self.root.geometry("500x600")
|
| 10 |
+
self.root.minsize(400, 400)
|
| 11 |
+
self.root.configure(bg="#f0f0f0")
|
| 12 |
+
|
| 13 |
+
# Chat frame with canvas for scrolling
|
| 14 |
+
self.frame = Frame(root, bg="#f0f0f0")
|
| 15 |
+
self.frame.pack(padx=10, pady=10, fill=BOTH, expand=True)
|
| 16 |
+
|
| 17 |
+
self.canvas = Canvas(self.frame, bg="#f0f0f0", highlightthickness=0)
|
| 18 |
+
self.scrollbar = Scrollbar(self.frame, orient="vertical", command=self.canvas.yview)
|
| 19 |
+
self.scrollable_frame = Frame(self.canvas, bg="#f0f0f0")
|
| 20 |
+
|
| 21 |
+
self.scrollable_frame.bind(
|
| 22 |
+
"<Configure>",
|
| 23 |
+
lambda e: self.canvas.configure(scrollregion=self.canvas.bbox("all"))
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
self.canvas.create_window((0, 0), window=self.scrollable_frame, anchor=NW)
|
| 27 |
+
self.canvas.configure(yscrollcommand=self.scrollbar.set)
|
| 28 |
+
|
| 29 |
+
self.canvas.pack(side=LEFT, fill=BOTH, expand=True)
|
| 30 |
+
self.scrollbar.pack(side=RIGHT, fill=Y)
|
| 31 |
+
|
| 32 |
+
# Entry box
|
| 33 |
+
self.entry = Entry(root, font=("Helvetica", 14), bd=2, relief="groove")
|
| 34 |
+
self.entry.pack(padx=10, pady=10, fill="x")
|
| 35 |
+
self.entry.bind("<Return>", self.send_message)
|
| 36 |
+
|
| 37 |
+
# Typing indicator
|
| 38 |
+
self.typing_label = Label(root, text="", bg="#f0f0f0", fg="gray", font=("Helvetica", 10))
|
| 39 |
+
self.typing_label.pack(pady=(0,5))
|
| 40 |
+
|
| 41 |
+
def send_message(self, event):
|
| 42 |
+
user_input = self.entry.get().strip()
|
| 43 |
+
if not user_input:
|
| 44 |
+
return
|
| 45 |
+
self.entry.delete(0, tk.END)
|
| 46 |
+
self.add_message(user_input, sender="user")
|
| 47 |
+
self.typing_label.config(text="Bot is typing...")
|
| 48 |
+
self.root.after(500, lambda: self.bot_reply(user_input))
|
| 49 |
+
|
| 50 |
+
def bot_reply(self, user_input):
|
| 51 |
+
response = chatbot_response(user_input)
|
| 52 |
+
self.typing_label.config(text="")
|
| 53 |
+
self.animate_bot_response(response)
|
| 54 |
+
|
| 55 |
+
def add_message(self, message, sender="bot"):
|
| 56 |
+
bubble = Label(self.scrollable_frame, text=message, wraplength=300, justify="left",
|
| 57 |
+
bg="#DCF8C6" if sender=="user" else "#FFFFFF",
|
| 58 |
+
fg="#000000", font=("Helvetica", 12), padx=10, pady=5, bd=1, relief="solid")
|
| 59 |
+
bubble.pack(anchor="e" if sender=="user" else "w", pady=5, padx=5)
|
| 60 |
+
self.canvas.update_idletasks()
|
| 61 |
+
self.canvas.yview_moveto(1.0)
|
| 62 |
+
|
| 63 |
+
def animate_bot_response(self, text, idx=0, message=""):
|
| 64 |
+
if idx < len(text):
|
| 65 |
+
message += text[idx]
|
| 66 |
+
if hasattr(self, "bot_bubble"):
|
| 67 |
+
self.bot_bubble.config(text=message)
|
| 68 |
+
else:
|
| 69 |
+
self.bot_bubble = Label(self.scrollable_frame, text=message, wraplength=300, justify="left",
|
| 70 |
+
bg="#FFFFFF", fg="#000000", font=("Helvetica", 12), padx=10, pady=5, bd=1, relief="solid")
|
| 71 |
+
self.bot_bubble.pack(anchor="w", pady=5, padx=5)
|
| 72 |
+
idx += 1
|
| 73 |
+
self.root.after(30, self.animate_bot_response, text, idx, message)
|
| 74 |
+
else:
|
| 75 |
+
del self.bot_bubble
|
| 76 |
+
self.canvas.update_idletasks()
|
| 77 |
+
self.canvas.yview_moveto(1.0)
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
root = tk.Tk()
|
| 81 |
+
app = ChatbotGUI(root)
|
| 82 |
+
root.mainloop()
|
src/predict.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
from preprocess import clean_text
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
# Load model & responses
|
| 6 |
+
model = joblib.load("models/lms_chatbot.joblib")
|
| 7 |
+
responses = joblib.load("models/responses.joblib")
|
| 8 |
+
|
| 9 |
+
def chatbot_response(user_input: str) -> str:
|
| 10 |
+
cleaned = clean_text(user_input)
|
| 11 |
+
tag = model.predict([cleaned])[0]
|
| 12 |
+
return random.choice(responses.get(tag, ["Sorry, I don't understand."]))
|
src/preprocess.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import re
|
| 2 |
+
import string
|
| 3 |
+
|
| 4 |
+
def clean_text(text: str) -> str:
|
| 5 |
+
"""Lowercase, remove punctuation, and clean text"""
|
| 6 |
+
text = text.lower()
|
| 7 |
+
text = re.sub(f"[{re.escape(string.punctuation)}]", "", text)
|
| 8 |
+
text = text.strip()
|
| 9 |
+
return text
|
src/train.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from sklearn.feature_extraction.text import TfidfVectorizer
|
| 3 |
+
from sklearn.naive_bayes import MultinomialNB
|
| 4 |
+
from sklearn.pipeline import Pipeline
|
| 5 |
+
from sklearn.model_selection import train_test_split
|
| 6 |
+
from sklearn.metrics import accuracy_score
|
| 7 |
+
import joblib
|
| 8 |
+
from preprocess import clean_text
|
| 9 |
+
|
| 10 |
+
# Load dataset
|
| 11 |
+
df = pd.read_csv("data/intents.csv")
|
| 12 |
+
|
| 13 |
+
# Clean text
|
| 14 |
+
df["patterns"] = df["patterns"].apply(clean_text)
|
| 15 |
+
|
| 16 |
+
# Features (patterns) and Labels (tags)
|
| 17 |
+
X = df["patterns"]
|
| 18 |
+
y = df["tag"]
|
| 19 |
+
|
| 20 |
+
# Train/Test Split
|
| 21 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 22 |
+
|
| 23 |
+
# Build pipeline
|
| 24 |
+
model = Pipeline([
|
| 25 |
+
("tfidf", TfidfVectorizer()),
|
| 26 |
+
("clf", MultinomialNB())
|
| 27 |
+
])
|
| 28 |
+
|
| 29 |
+
# Train
|
| 30 |
+
model.fit(X_train, y_train)
|
| 31 |
+
|
| 32 |
+
# Evaluate
|
| 33 |
+
y_pred = model.predict(X_test)
|
| 34 |
+
print("Accuracy:", accuracy_score(y_test, y_pred))
|
| 35 |
+
|
| 36 |
+
# Save model & responses
|
| 37 |
+
joblib.dump(model, "models/lms_chatbot.joblib")
|
| 38 |
+
|
| 39 |
+
# Save responses by tag
|
| 40 |
+
responses = df.groupby("tag")["responses"].apply(list).to_dict()
|
| 41 |
+
joblib.dump(responses, "models/responses.joblib")
|
| 42 |
+
|
| 43 |
+
print("✅ Training complete. Model and responses saved.")
|
ssh
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN OPENSSH PRIVATE KEY-----
|
| 2 |
+
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
|
| 3 |
+
QyNTUxOQAAACAu2M7glBJCZlGCpulYhByrlxxAnRt5fUP27QYQmqPN/gAAAJh15fi6deX4
|
| 4 |
+
ugAAAAtzc2gtZWQyNTUxOQAAACAu2M7glBJCZlGCpulYhByrlxxAnRt5fUP27QYQmqPN/g
|
| 5 |
+
AAAED6iXh8YIMs76hS0gAkFg3XkYck/gm3Bu93ax77Vj+QtS7YzuCUEkJmUYKm6ViEHKuX
|
| 6 |
+
HECdG3l9Q/btBhCao83+AAAAFXZpdmVrc25oOTMzQGdtYWlsLmNvbQ==
|
| 7 |
+
-----END OPENSSH PRIVATE KEY-----
|
ssh.pub
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC7YzuCUEkJmUYKm6ViEHKuXHECdG3l9Q/btBhCao83+ viveksnh933@gmail.com
|