Manyue-DataScientist commited on
Commit
62f14a6
·
verified ·
1 Parent(s): bea2a2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -65
app.py CHANGED
@@ -12,51 +12,9 @@ st.set_page_config(
12
  if 'messages' not in st.session_state:
13
  st.session_state.messages = []
14
 
15
- def load_knowledge_base():
16
- """Load the knowledge base from JSON file"""
17
- try:
18
- with open('knowledge_base.json', 'r', encoding='utf-8') as f:
19
- return json.load(f)
20
- except Exception as e:
21
- st.error(f"Error loading knowledge base: {str(e)}")
22
- return {}
23
-
24
- def get_context(query: str, knowledge_base: dict) -> str:
25
- """Get relevant context from knowledge base based on query"""
26
- query_lower = query.lower()
27
- contexts = []
28
-
29
- # Project context
30
- if "project" in query_lower:
31
- if "projects" in knowledge_base:
32
- contexts.extend([
33
- f"{name}: {desc}"
34
- for name, desc in knowledge_base["projects"].items()
35
- ])
36
-
37
- # Skills context
38
- elif any(keyword in query_lower for keyword in ["skill", "experience", "capability"]):
39
- if "personal_details" in knowledge_base and "skills" in knowledge_base["personal_details"]:
40
- contexts.extend([
41
- f"{skill}: {desc}"
42
- for skill, desc in knowledge_base["personal_details"]["skills"].items()
43
- ])
44
-
45
- # Default context
46
- else:
47
- contexts = [
48
- f"Name: {knowledge_base.get('personal_details', {}).get('full_name', 'Manyue')}",
49
- "Summary: I am an aspiring AI/ML engineer with experience in Python, Machine Learning, and Data Analysis."
50
- ]
51
-
52
- return "\n".join(contexts)
53
-
54
  def main():
55
  st.title("Portfolio Chatbot Testing Interface")
56
- st.write("Test the chatbot's responses and interaction patterns")
57
-
58
- # Load knowledge base
59
- knowledge_base = load_knowledge_base()
60
 
61
  # Create two columns for layout
62
  col1, col2 = st.columns([2, 1])
@@ -73,13 +31,10 @@ def main():
73
  # Add user message to chat history
74
  st.session_state.messages.append({"role": "user", "content": prompt})
75
 
76
- # Get context for the query
77
- context = get_context(prompt, knowledge_base)
78
-
79
- # For testing, just echo back the context
80
- response = f"TEST RESPONSE: Here's what I know about this:\n\n{context}"
81
 
82
- # Display assistant response in chat message container
83
  with st.chat_message("assistant"):
84
  st.markdown(response)
85
 
@@ -88,24 +43,9 @@ def main():
88
 
89
  with col2:
90
  st.subheader("Testing Tools")
91
- if st.button("Clear Chat History"):
92
  st.session_state.messages = []
93
  st.experimental_rerun()
94
-
95
- st.subheader("Sample Questions")
96
- if st.button("Tell me about your ML projects"):
97
- st.session_state.messages.append({
98
- "role": "user",
99
- "content": "Tell me about your ML projects"
100
- })
101
- st.experimental_rerun()
102
-
103
- if st.button("What are your Python skills?"):
104
- st.session_state.messages.append({
105
- "role": "user",
106
- "content": "What are your Python skills?"
107
- })
108
- st.experimental_rerun()
109
 
110
  if __name__ == "__main__":
111
  main()
 
12
  if 'messages' not in st.session_state:
13
  st.session_state.messages = []
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def main():
16
  st.title("Portfolio Chatbot Testing Interface")
17
+ st.write("Basic testing version")
 
 
 
18
 
19
  # Create two columns for layout
20
  col1, col2 = st.columns([2, 1])
 
31
  # Add user message to chat history
32
  st.session_state.messages.append({"role": "user", "content": prompt})
33
 
34
+ # Simple echo response for testing
35
+ response = f"You asked: {prompt}"
 
 
 
36
 
37
+ # Display assistant response
38
  with st.chat_message("assistant"):
39
  st.markdown(response)
40
 
 
43
 
44
  with col2:
45
  st.subheader("Testing Tools")
46
+ if st.button("Clear Chat"):
47
  st.session_state.messages = []
48
  st.experimental_rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  if __name__ == "__main__":
51
  main()