shukdevdatta123 commited on
Commit
cd6b7dc
·
verified ·
1 Parent(s): bc50dbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -50,7 +50,6 @@ def read_docx(file):
50
 
51
  @st.cache_resource(show_spinner=False)
52
  def load_data(uploaded_files):
53
- # Create the LLM instance outside the cache
54
  llm = OpenAI(model="gpt-3.5-turbo", temperature=0.5,
55
  system_prompt="You are an expert on the Streamlit Python library and your job is to answer technical questions. Assume that all questions are related to the Streamlit Python library. Keep your answers technical and based on facts – do not hallucinate features.")
56
 
@@ -84,9 +83,17 @@ def save_conversation():
84
  def load_conversations():
85
  if os.path.exists("conversations.json"):
86
  with open("conversations.json", "r") as f:
87
- conversations = [json.loads(line) for line in f]
 
 
 
 
 
 
 
 
88
  # Filter conversations based on the current username
89
- return [conv for conv in conversations if conv["username"] == st.session_state.username]
90
  return []
91
 
92
  # Function to delete selected conversations
@@ -175,4 +182,4 @@ if st.session_state.show_conversations:
175
  else:
176
  st.sidebar.write("No previous conversations found.")
177
  else:
178
- st.sidebar.write("Previous conversations are hidden. Click 'Toggle Previous Conversations' to show.")
 
50
 
51
  @st.cache_resource(show_spinner=False)
52
  def load_data(uploaded_files):
 
53
  llm = OpenAI(model="gpt-3.5-turbo", temperature=0.5,
54
  system_prompt="You are an expert on the Streamlit Python library and your job is to answer technical questions. Assume that all questions are related to the Streamlit Python library. Keep your answers technical and based on facts – do not hallucinate features.")
55
 
 
83
  def load_conversations():
84
  if os.path.exists("conversations.json"):
85
  with open("conversations.json", "r") as f:
86
+ conversations = []
87
+ for line in f:
88
+ try:
89
+ conversation = json.loads(line)
90
+ conversations.append(conversation)
91
+ except json.JSONDecodeError:
92
+ st.error("Error decoding JSON from conversations file. Please check the file.")
93
+ continue
94
+
95
  # Filter conversations based on the current username
96
+ return [conv for conv in conversations if isinstance(conv, dict) and "username" in conv and conv["username"] == st.session_state.username]
97
  return []
98
 
99
  # Function to delete selected conversations
 
182
  else:
183
  st.sidebar.write("No previous conversations found.")
184
  else:
185
+ st.sidebar.write("Previous conversations are hidden. Click 'Toggle Previous Conversations' to show.")