Clone77 commited on
Commit
57719a3
·
verified ·
1 Parent(s): c87a29a

Update pages/deep_learning.py

Browse files
Files changed (1) hide show
  1. pages/deep_learning.py +32 -29
pages/deep_learning.py CHANGED
@@ -43,35 +43,38 @@ deep_seek = ChatHuggingFace(
43
  task='conversational'
44
  )
45
  PAGE_KEY = "deep_learning_chat_history"
46
- # --- Session State ---
47
- if PAGE_KEY not in st.session_state:
48
- st.session_state[PAGE_KEY] = []
49
-
50
- # --- Chat Form ---
51
- with st.form(key="chat_form"):
52
- user_input = st.text_input("Ask your question:")
53
- submit = st.form_submit_button("Send")
54
-
55
- # --- Chat Logic ---
56
- if submit and user_input:
57
- # Add system context
58
- system_prompt = f"Act as a deep 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 deep learning then you must not answer and tell that it is out of topic query."
59
-
60
- # Create message list
61
- messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
62
-
63
- # Get model response
64
- result = deep_seek.invoke(messages)
65
-
66
- # Append to history
67
- st.session_state[PAGE_KEY].append((user_input, result.content))
68
-
69
- # --- Display Chat History ---
70
- st.subheader("🗨️ Chat History")
71
- for user, bot in st.session_state[PAGE_KEY]:
72
- st.markdown(f"**You:** {user}")
73
- st.markdown(f"**Mentor:** {bot}")
74
- st.markdown("---")
 
 
 
75
  # for i, (user, bot) in enumerate(st.session_state.chat_history):
76
  # st.markdown(f"**You:** {user}")
77
  # st.markdown(f"**Mentor:** {bot}")
 
43
  task='conversational'
44
  )
45
  PAGE_KEY = "deep_learning_chat_history"
46
+ try:
47
+ # --- Session State ---
48
+ if PAGE_KEY not in st.session_state:
49
+ st.session_state[PAGE_KEY] = []
50
+
51
+ # --- Chat Form ---
52
+ with st.form(key="chat_form"):
53
+ user_input = st.text_input("Ask your question:")
54
+ submit = st.form_submit_button("Send")
55
+
56
+ # --- Chat Logic ---
57
+ if submit and user_input:
58
+ # Add system context
59
+ system_prompt = f"Act as a deep 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 deep learning then you must not answer and tell that it is out of topic query."
60
+
61
+ # Create message list
62
+ messages = [SystemMessage(content=system_prompt), HumanMessage(content=user_input)]
63
+
64
+ # Get model response
65
+ result = deep_seek.invoke(messages)
66
+
67
+ # Append to history
68
+ st.session_state[PAGE_KEY].append((user_input, result.content))
69
+
70
+ # --- Display Chat History ---
71
+ st.subheader("🗨️ Chat History")
72
+ for user, bot in st.session_state[PAGE_KEY]:
73
+ st.markdown(f"**You:** {user}")
74
+ st.markdown(f"**Mentor:** {bot}")
75
+ st.markdown("---")
76
+ except:
77
+ st.warning('The token limit has reached please revisit in 24 hours!')
78
  # for i, (user, bot) in enumerate(st.session_state.chat_history):
79
  # st.markdown(f"**You:** {user}")
80
  # st.markdown(f"**Mentor:** {bot}")