Clone77 commited on
Commit
6d9e70f
·
verified ·
1 Parent(s): 8882589

Update pages/python.py

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