Clone77 commited on
Commit
8882589
·
verified ·
1 Parent(s): 8b5b1b3

Update pages/machine_learning.py

Browse files
Files changed (1) hide show
  1. pages/machine_learning.py +32 -29
pages/machine_learning.py CHANGED
@@ -46,32 +46,35 @@ deep_seek = ChatHuggingFace(
46
 
47
  # --- Session State ---
48
  PAGE_KEY = "machine_learning_chat_history"
49
- # --- Session State ---
50
- if PAGE_KEY not in st.session_state:
51
- st.session_state[PAGE_KEY] = []
52
-
53
- # --- Chat Form ---
54
- with st.form(key="chat_form"):
55
- user_input = st.text_input("Ask your question:")
56
- submit = st.form_submit_button("Send")
57
-
58
- # --- Chat Logic ---
59
- if submit and user_input:
60
- # Add system context
61
- system_prompt = f"Act as a machine learning mentor who has {experience_label} years of experience who teaches in a very friendly manner and also tells everything in within 150 words. If any question is asked other than machine learning tell politely that this is out of the topic question"
62
-
63
- # Create message list
64
- messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
65
-
66
- # Get model response
67
- result = deep_seek.invoke(messages)
68
-
69
- # Append to history
70
- st.session_state[PAGE_KEY].append((user_input, result.content))
71
-
72
- # --- Display Chat History ---
73
- st.subheader("🗨️ Chat History")
74
- for user, bot in st.session_state[PAGE_KEY]:
75
- st.markdown(f"**You:** {user}")
76
- st.markdown(f"**Mentor:** {bot}")
77
- st.markdown("---")
 
 
 
 
46
 
47
  # --- Session State ---
48
  PAGE_KEY = "machine_learning_chat_history"
49
+ try:
50
+ # --- Session State ---
51
+ if PAGE_KEY not in st.session_state:
52
+ st.session_state[PAGE_KEY] = []
53
+
54
+ # --- Chat Form ---
55
+ with st.form(key="chat_form"):
56
+ user_input = st.text_input("Ask your question:")
57
+ submit = st.form_submit_button("Send")
58
+
59
+ # --- Chat Logic ---
60
+ if submit and user_input:
61
+ # Add system context
62
+ system_prompt = f"Act as a machine learning mentor who has {experience_label} years of experience who teaches in a very friendly manner and also tells everything in within 150 words. If any question is asked other than machine learning tell politely that this is out of the topic question"
63
+
64
+ # Create message list
65
+ messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
66
+
67
+ # Get model response
68
+ result = deep_seek.invoke(messages)
69
+
70
+ # Append to history
71
+ st.session_state[PAGE_KEY].append((user_input, result.content))
72
+
73
+ # --- Display Chat History ---
74
+ st.subheader("🗨️ Chat History")
75
+ for user, bot in st.session_state[PAGE_KEY]:
76
+ st.markdown(f"**You:** {user}")
77
+ st.markdown(f"**Mentor:** {bot}")
78
+ st.markdown("---")
79
+ except:
80
+ st.warning('The token limit has reached please revisit in 24 hours!')