Spaces:
Sleeping
Sleeping
Update pages/excel.py
Browse files- pages/excel.py +32 -29
pages/excel.py
CHANGED
|
@@ -46,32 +46,35 @@ deep_seek = ChatHuggingFace(
|
|
| 46 |
|
| 47 |
# --- Session State ---
|
| 48 |
PAGE_KEY = "excel_chat_history"
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
st.session_state
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
st.
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# --- Session State ---
|
| 48 |
PAGE_KEY = "excel_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 microsoft excel 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 microsoft excel 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!')
|