Samarth4023 commited on
Commit
614f6a8
·
1 Parent(s): 6a7e1d0

Optimized chatbot.py

Browse files
Files changed (2) hide show
  1. chat_history.json +1 -1
  2. chatbot.py +51 -11
chat_history.json CHANGED
@@ -1 +1 @@
1
- ["[2025-03-14 19:35:09] You: Hi", "[2025-03-14 19:35:09] Bot: Hey", "[2025-03-14 19:35:39] You: I need help.", "[2025-03-14 19:35:39] Bot: Sure, what do you need help with?", "[2025-03-14 19:37:41] You: How old are You ?", "[2025-03-14 19:37:41] Bot: Age is just a number for me.", "[2025-03-14 19:38:21] You: hi", "[2025-03-14 19:38:21] Bot: Nothing much", "[2025-03-14 19:38:46] You: Budget", "[2025-03-14 19:38:46] Bot: To make a budget, start by tracking your income and expenses. Then, allocate your income towards essential expenses like rent, food, and bills. Next, allocate some of your income towards savings and debt repayment. Finally, allocate the remainder of your income towards discretionary expenses like entertainment and hobbies.", "[2025-03-14 19:47:18] You: I need help.", "[2025-03-14 19:47:18] Bot: I'm here to help. What's the problem?", "[2025-03-14 19:51:35] You: Hi", "[2025-03-14 19:51:35] Bot: Nothing much", "[2025-03-14 19:54:12] You: Recommend some excercises.", "[2025-03-14 19:54:12] Bot: Setting boundaries with digital devices can improve sleep, productivity, and overall well-being."]
 
1
+ ["[2025-03-15 12:02:53] You: Hi", "[2025-03-15 12:02:53] Bot: Hi there"]
chatbot.py CHANGED
@@ -85,25 +85,47 @@ with st.sidebar:
85
 
86
  if st.button("ℹ️ About"):
87
  st.session_state.show_about = True
 
88
 
89
  # Modal Windows (Chat History & About)
90
- history_modal = Modal("Chat History", key="history_modal")
91
- about_modal = Modal("About", key="about_modal")
92
 
93
  # Display chat history without affecting the chat window
94
  if st.session_state.show_history:
95
  with history_modal.container():
96
- st.subheader("🕰 Chat History")
97
- for chat in st.session_state.chat_history[-10:]: # Show last 10 messages
98
- st.write(chat)
 
 
 
 
 
 
 
 
 
 
 
99
  if st.button("Close", key="close_history"):
100
- st.session_state.show_history = False # Close modal without resetting UI
101
  st.rerun()
102
 
103
  if st.session_state.show_about:
104
  with about_modal.container():
105
- st.subheader("ℹ️ About")
106
- st.info("This is an intent-based chatbot powered by BERT, built using Streamlit.")
 
 
 
 
 
 
 
 
 
 
107
  if st.button("Close", key="close_about"):
108
  st.session_state.show_about = False # Close modal without resetting UI
109
  st.rerun()
@@ -113,6 +135,7 @@ st.title("🤖 AI Chatbot")
113
  st.markdown("### Talk to me, I'm listening...")
114
 
115
  rain(emoji="💬", font_size=10, falling_speed=5, animation_length="infinite")
 
116
 
117
  # Chat Input with Enter Button
118
  with st.form("chat_form", clear_on_submit=True):
@@ -141,8 +164,25 @@ if submit_button and chat_input:
141
  # Style customization
142
  st.markdown("""
143
  <style>
144
- .stChatMessage {padding: 10px; border-radius: 10px; background-color: #000000;}
145
- .stChatMessageUser {background-color: #000000;}
146
- .stChatMessageAssistant {background-color: #000000;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  </style>
148
  """, unsafe_allow_html=True)
 
85
 
86
  if st.button("ℹ️ About"):
87
  st.session_state.show_about = True
88
+ st.caption("🚀 Built with ❤️ by AI Enthusiast")
89
 
90
  # Modal Windows (Chat History & About)
91
+ history_modal = Modal("📜Chat History", key="history_modal")
92
+ about_modal = Modal("ℹ️About", key="about_modal")
93
 
94
  # Display chat history without affecting the chat window
95
  if st.session_state.show_history:
96
  with history_modal.container():
97
+ if st.session_state.chat_history:
98
+ for chat in st.session_state.chat_history[-10:]: # Show last 10 messages
99
+ st.write(chat)
100
+ else:
101
+ st.info("No chat history available.")
102
+
103
+ # Clear History Button
104
+ if st.button("🗑 Clear History", key="clear_history"):
105
+ st.session_state.chat_history = [] # Clear session history
106
+ if os.path.exists(CHAT_HISTORY_FILE):
107
+ os.remove(CHAT_HISTORY_FILE) # Delete saved file
108
+ st.rerun() # Refresh UI to reflect changes
109
+
110
+ # Close Modal Button
111
  if st.button("Close", key="close_history"):
112
+ st.session_state.show_history = False
113
  st.rerun()
114
 
115
  if st.session_state.show_about:
116
  with about_modal.container():
117
+ st.info("""This chatbot is powered by a deep learning approach using Hugging Face Transformers and a BERT model for intent recognition.
118
+ It understands user queries by predicting intent and responding with predefined answers based on a trained dataset.
119
+
120
+ ✅ Natural Language Processing (NLP)​
121
+
122
+ 🔹 Transformers (Hugging Face) 🤖 – BERT-based intent classification​
123
+
124
+ ✅ Deep Learning​
125
+
126
+ 🔹 PyTorch 🔥 – Model training & fine-tuning
127
+ """)
128
+
129
  if st.button("Close", key="close_about"):
130
  st.session_state.show_about = False # Close modal without resetting UI
131
  st.rerun()
 
135
  st.markdown("### Talk to me, I'm listening...")
136
 
137
  rain(emoji="💬", font_size=10, falling_speed=5, animation_length="infinite")
138
+ rain(emoji="❄️", font_size=10, falling_speed=5, animation_length="infinite")
139
 
140
  # Chat Input with Enter Button
141
  with st.form("chat_form", clear_on_submit=True):
 
164
  # Style customization
165
  st.markdown("""
166
  <style>
167
+
168
+ /* Fix Modal Height & Enable Scroll */
169
+ div[data-modal-container="true"] {
170
+ position: fixed !important;
171
+ top: 5% !important; /* Adjust this value to position it higher */
172
+ color: #000000;
173
+ max-height: 1000px !important; /* Set max height */
174
+ }
175
+
176
+ /* Ensure the close button stays visible */
177
+ div[data-modal-container="true"] button {
178
+ position: sticky;
179
+ bottom: 10px;
180
+ background-color: #000000;
181
+ color: white;
182
+ }
183
+
184
+ .stChatMessage {padding: 10px; border-radius: 10px; background-color: #900C3F;}
185
+ .stChatMessageUser {background-color: #900C3F;}
186
+ .stChatMessageAssistant {background-color: #900C3F;}
187
  </style>
188
  """, unsafe_allow_html=True)