hmrizal commited on
Commit
89240e9
·
verified ·
1 Parent(s): d23006f

change_model allow_dangerous_deserialization to true

Browse files
Files changed (1) hide show
  1. app.py +26 -24
app.py CHANGED
@@ -347,31 +347,33 @@ class ChatBot:
347
  return f"Error pemrosesan file: {str(e)}"
348
 
349
  def change_model(self, model_key):
350
- """Change the model being used and recreate the chain if necessary"""
351
- if model_key == self.model_key:
352
- return f"Model {model_key} sudah digunakan."
353
-
354
- self.model_key = model_key
355
 
356
- # If we have an active session with a file already loaded, recreate the chain
357
- if self.csv_file_path:
358
- try:
359
- # Load existing database
360
- db_path = f"{self.user_dir}/db_faiss"
361
- embeddings = HuggingFaceEmbeddings(
362
- model_name='sentence-transformers/all-MiniLM-L6-v2',
363
- model_kwargs={'device': 'cpu'}
364
- )
365
- db = FAISS.load_local(db_path, embeddings)
366
-
367
- # Create new chain with the selected model
368
- self.chain = create_conversational_chain(db, self.csv_file_path, self.model_key)
369
-
370
- return f"Model berhasil diubah ke {model_key}."
371
- except Exception as e:
372
- return f"Error mengubah model: {str(e)}"
373
- else:
374
- return f"Model diubah ke {model_key}. Silakan upload file CSV untuk memulai."
 
 
 
 
375
 
376
  def chat(self, message, history):
377
  if self.chain is None:
 
347
  return f"Error pemrosesan file: {str(e)}"
348
 
349
  def change_model(self, model_key):
350
+ """Change the model being used and recreate the chain if necessary"""
351
+ if model_key == self.model_key:
352
+ return f"Model {model_key} sudah digunakan."
 
 
353
 
354
+ self.model_key = model_key
355
+
356
+ # If we have an active session with a file already loaded, recreate the chain
357
+ if self.csv_file_path:
358
+ try:
359
+ # Load existing database
360
+ db_path = f"{self.user_dir}/db_faiss"
361
+ embeddings = HuggingFaceEmbeddings(
362
+ model_name='sentence-transformers/all-MiniLM-L6-v2',
363
+ model_kwargs={'device': 'cpu'}
364
+ )
365
+
366
+ # Tambahkan flag allow_dangerous_deserialization=True
367
+ db = FAISS.load_local(db_path, embeddings, allow_dangerous_deserialization=True)
368
+
369
+ # Create new chain with the selected model
370
+ self.chain = create_conversational_chain(db, self.csv_file_path, self.model_key)
371
+
372
+ return f"Model berhasil diubah ke {model_key}."
373
+ except Exception as e:
374
+ return f"Error mengubah model: {str(e)}"
375
+ else:
376
+ return f"Model diubah ke {model_key}. Silakan upload file CSV untuk memulai."
377
 
378
  def chat(self, message, history):
379
  if self.chain is None: