Vivekkrishu commited on
Commit
b84ccee
·
1 Parent(s): 61d37c6
Files changed (1) hide show
  1. app.py +31 -14
app.py CHANGED
@@ -1,21 +1,38 @@
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()
 
 
1
+ # app.py
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
  # Keep conversation history
11
  history = []
12
 
13
+ def chatbot_response(user_input):
14
+ clean_input = clean_text(user_input)
15
+ tag = model.predict([clean_input])[0]
16
+ bot_reply = responses.get(tag, ["Sorry, I don't understand."])[0]
17
+
18
+ # Append to history
19
+ history.append((user_input, bot_reply))
20
+
21
+ # Format chat history nicely
22
+ formatted_history = ""
23
+ for user_msg, bot_msg in history:
24
+ formatted_history += f"**You:** {user_msg}\n**Bot:** {bot_msg}\n\n"
25
+
26
+ return formatted_history
27
 
28
+ # Gradio Interface
29
+ demo = gr.Interface(
30
+ fn=chatbot_response,
31
+ inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
32
+ outputs=gr.Markdown(),
33
+ title="LMS Chatbot",
34
+ description="Ask anything about LMS and get automated responses."
35
+ )
36
 
37
+ if __name__ == "__main__":
38
+ demo.launch()