Spaces:
Sleeping
Sleeping
Update pages/deep_learning.py
Browse files- 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 |
-
|
47 |
-
|
48 |
-
st.session_state
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
st.
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
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}")
|