Vivekkrishu commited on
Commit
61d37c6
·
1 Parent(s): 4574d7c
Files changed (1) hide show
  1. app.py +16 -21
app.py CHANGED
@@ -1,26 +1,21 @@
1
- # app.py at the root of your project
2
  import gradio as gr
3
- import joblib
4
- from src.preprocess import clean_text
5
 
6
- # Load trained model and responses
7
- model = joblib.load("models/lms_chatbot.joblib")
8
- responses = joblib.load("models/responses.joblib")
9
 
10
- def chatbot_response(user_input):
11
- """Predict the tag and return the corresponding response."""
12
- clean_input = clean_text(user_input)
13
- tag = model.predict([clean_input])[0]
14
- return responses.get(tag, ["Sorry, I don't understand."])[0]
 
15
 
16
- # Gradio interface
17
- demo = gr.Interface(
18
- fn=chatbot_response,
19
- inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
20
- outputs="text",
21
- title="LMS Chatbot",
22
- description="Ask anything about LMS and get automated responses."
23
- )
24
 
25
- if __name__ == "__main__":
26
- demo.launch()
 
1
+ # app.py at the root
2
  import gradio as gr
3
+ from src.predict import chatbot_response
 
4
 
5
+ # Keep conversation history
6
+ history = []
 
7
 
8
+ def chat(user_input):
9
+ global history
10
+ response = chatbot_response(user_input)
11
+ history.append(("You", user_input))
12
+ history.append(("Bot", response))
13
+ return history, history
14
 
15
+ # Gradio Chat Interface
16
+ demo = gr.ChatInterface(fn=chat,
17
+ title="LMS Chatbot",
18
+ description="Chat with the LMS Chatbot",
19
+ height=600)
 
 
 
20
 
21
+ demo.launch()