sainathBelagavi commited on
Commit
0f971cd
·
verified ·
1 Parent(s): 1d4d8a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -19
app.py CHANGED
@@ -52,21 +52,7 @@ def reset_conversation():
52
  '''
53
  st.session_state.conversation = []
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)
@@ -86,14 +72,13 @@ if st.session_state.prev_option != selected_model:
86
  st.session_state.messages = []
87
  st.session_state.prev_option = selected_model
88
 
89
- reset_conversation()
 
 
90
 
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"]):
99
  st.markdown(message["content"])
 
52
  '''
53
  st.session_state.conversation = []
54
  st.session_state.messages = []
55
+ st.experimental_rerun() # Add this line to rerun the app after reset
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  models = [key for key in model_links.keys()]
58
  selected_model = st.sidebar.selectbox("Select Model", models)
 
72
  st.session_state.messages = []
73
  st.session_state.prev_option = selected_model
74
 
75
+ # Load the conversation history from the file
76
+ if "messages" not in st.session_state:
77
+ st.session_state.messages = load_conversation_history()
78
 
79
  repo_id = model_links[selected_model]
80
  st.subheader(f'{selected_model}')
81
 
 
 
 
82
  for message in st.session_state.messages:
83
  with st.chat_message(message["role"]):
84
  st.markdown(message["content"])