Update app.py
Browse files
app.py
CHANGED
@@ -1,65 +1,51 @@
|
|
1 |
import streamlit as st
|
2 |
-
import
|
3 |
-
import pkg_resources
|
4 |
|
5 |
-
# Page
|
6 |
-
st.set_page_config(
|
7 |
-
page_title="Portfolio Chatbot Test",
|
8 |
-
page_icon="🤖",
|
9 |
-
layout="wide"
|
10 |
-
)
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
st.
|
15 |
-
installed_packages = [f"{pkg.key} {pkg.version}" for pkg in pkg_resources.working_set]
|
16 |
-
st.write(installed_packages)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
if 'messages' not in st.session_state:
|
27 |
-
st.session_state.messages = []
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
# Accept user input
|
44 |
-
if prompt := st.chat_input("What would you like to know?"):
|
45 |
-
# Add user message to chat history
|
46 |
-
st.session_state.messages.append({"role": "user", "content": prompt})
|
47 |
-
|
48 |
-
# Simple echo response for testing
|
49 |
-
response = f"You asked: {prompt}"
|
50 |
-
|
51 |
-
# Display assistant response
|
52 |
-
with st.chat_message("assistant"):
|
53 |
-
st.markdown(response)
|
54 |
-
|
55 |
-
# Add assistant response to chat history
|
56 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
st.experimental_rerun()
|
63 |
|
64 |
-
|
65 |
-
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import json
|
|
|
3 |
|
4 |
+
# Page config
|
5 |
+
st.set_page_config(page_title="Chatbot Test", layout="wide")
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
# Initialize chat history
|
8 |
+
if "messages" not in st.session_state:
|
9 |
+
st.session_state.messages = []
|
|
|
|
|
10 |
|
11 |
+
# Load knowledge base
|
12 |
+
def load_knowledge_base():
|
13 |
+
try:
|
14 |
+
with open("knowledge_base.json", "r", encoding="utf-8") as f:
|
15 |
+
return json.load(f)
|
16 |
+
except Exception as e:
|
17 |
+
st.error(f"Error loading knowledge base: {str(e)}")
|
18 |
+
return {}
|
19 |
|
20 |
+
kb = load_knowledge_base()
|
|
|
|
|
21 |
|
22 |
+
# Main UI
|
23 |
+
st.title("Portfolio Chat Test")
|
24 |
+
|
25 |
+
# Chat interface
|
26 |
+
for message in st.session_state.messages:
|
27 |
+
with st.chat_message(message["role"]):
|
28 |
+
st.write(message["content"])
|
29 |
+
|
30 |
+
# Chat input
|
31 |
+
if prompt := st.chat_input("Ask me anything..."):
|
32 |
+
# Add user message
|
33 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
34 |
|
35 |
+
# Generate simple response from knowledge base
|
36 |
+
if "projects" in kb and "project" in prompt.lower():
|
37 |
+
response = "Here are my projects: " + ", ".join(kb["projects"].keys())
|
38 |
+
elif "skills" in prompt.lower():
|
39 |
+
response = "I have experience in Python, ML, and Data Analysis."
|
40 |
+
else:
|
41 |
+
response = "I understand you're asking about: " + prompt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
+
# Add assistant response
|
44 |
+
with st.chat_message("assistant"):
|
45 |
+
st.write(response)
|
46 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
47 |
|
48 |
+
# Clear chat button
|
49 |
+
if st.sidebar.button("Clear Chat"):
|
50 |
+
st.session_state.messages = []
|
51 |
+
st.rerun()
|