Spaces:
Runtime error
Runtime error
for marinating the chat history via pickle
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import sys
|
|
|
5 |
|
6 |
st.title("CODEFUSSION ☄")
|
7 |
|
@@ -53,6 +54,20 @@ def reset_conversation():
|
|
53 |
st.session_state.messages = []
|
54 |
return None
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
models = [key for key in model_links.keys()]
|
57 |
selected_model = st.sidebar.selectbox("Select Model", models)
|
58 |
temp_values = st.sidebar.slider('Select a temperature value', 0.0, 1.0, (0.5))
|
@@ -76,8 +91,8 @@ reset_conversation()
|
|
76 |
repo_id = model_links[selected_model]
|
77 |
st.subheader(f'{selected_model}')
|
78 |
|
79 |
-
|
80 |
-
|
81 |
|
82 |
for message in st.session_state.messages:
|
83 |
with st.chat_message(message["role"]):
|
@@ -104,4 +119,7 @@ if prompt := st.chat_input(f"Hi I'm {selected_model}, How can I help you today?"
|
|
104 |
stream=True
|
105 |
)
|
106 |
response = st.write_stream(output)
|
107 |
-
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
|
|
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
import sys
|
5 |
+
import pickle
|
6 |
|
7 |
st.title("CODEFUSSION ☄")
|
8 |
|
|
|
54 |
st.session_state.messages = []
|
55 |
return None
|
56 |
|
57 |
+
def load_conversation_history():
|
58 |
+
history_file = "conversation_history.pickle"
|
59 |
+
if os.path.exists(history_file):
|
60 |
+
with open(history_file, "rb") as f:
|
61 |
+
conversation_history = pickle.load(f)
|
62 |
+
else:
|
63 |
+
conversation_history = []
|
64 |
+
return conversation_history
|
65 |
+
|
66 |
+
def save_conversation_history(conversation_history):
|
67 |
+
history_file = "conversation_history.pickle"
|
68 |
+
with open(history_file, "wb") as f:
|
69 |
+
pickle.dump(conversation_history, f)
|
70 |
+
|
71 |
models = [key for key in model_links.keys()]
|
72 |
selected_model = st.sidebar.selectbox("Select Model", models)
|
73 |
temp_values = st.sidebar.slider('Select a temperature value', 0.0, 1.0, (0.5))
|
|
|
91 |
repo_id = model_links[selected_model]
|
92 |
st.subheader(f'{selected_model}')
|
93 |
|
94 |
+
# Load the conversation history from the file
|
95 |
+
st.session_state.messages = load_conversation_history()
|
96 |
|
97 |
for message in st.session_state.messages:
|
98 |
with st.chat_message(message["role"]):
|
|
|
119 |
stream=True
|
120 |
)
|
121 |
response = st.write_stream(output)
|
122 |
+
st.session_state.messages.append({"role": "assistant", "content": response})
|
123 |
+
|
124 |
+
# Save the updated conversation history to the file
|
125 |
+
save_conversation_history(st.session_state.messages)
|