CogwiseAI commited on
Commit
67d9e54
·
1 Parent(s): 615c973

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -73,6 +73,12 @@ st.markdown("""
73
  </style>
74
  """, unsafe_allow_html=True)
75
 
 
 
 
 
 
 
76
  def write_top_bar():
77
  col1, col2, col3 = st.columns([1,10,2])
78
  with col1:
@@ -103,12 +109,6 @@ def handle_input():
103
  chat_history = st.session_state["chat_history"]
104
  if len(chat_history) == MAX_HISTORY_LENGTH:
105
  chat_history = chat_history[:-1]
106
-
107
- with open('model_saved.pkl', 'rb') as f:
108
- model = pickle.load(f)
109
- if not hasattr(model, 'predict'):
110
- st.error("The loaded model does not have a predict method.")
111
- return
112
 
113
  def generate_response(question: str) -> str:
114
  return model.predict([question])[0]
 
73
  </style>
74
  """, unsafe_allow_html=True)
75
 
76
+ # Load the model outside the handle_input() function
77
+ with open('model_saved.pkl', 'rb') as f:
78
+ model = pickle.load(f)
79
+ if not hasattr(model, 'predict'):
80
+ st.error("The loaded model does not have a predict method.")
81
+
82
  def write_top_bar():
83
  col1, col2, col3 = st.columns([1,10,2])
84
  with col1:
 
109
  chat_history = st.session_state["chat_history"]
110
  if len(chat_history) == MAX_HISTORY_LENGTH:
111
  chat_history = chat_history[:-1]
 
 
 
 
 
 
112
 
113
  def generate_response(question: str) -> str:
114
  return model.predict([question])[0]