Spaces:
Sleeping
Sleeping
Samarth4023 commited on
Commit ·
614f6a8
1
Parent(s): 6a7e1d0
Optimized chatbot.py
Browse files- chat_history.json +1 -1
- chatbot.py +51 -11
chat_history.json
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
["[2025-03-
|
|
|
|
| 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.
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
if st.button("Close", key="close_history"):
|
| 100 |
-
st.session_state.show_history = False
|
| 101 |
st.rerun()
|
| 102 |
|
| 103 |
if st.session_state.show_about:
|
| 104 |
with about_modal.container():
|
| 105 |
-
st.
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|