Spaces:
Running
Running
update indentation change_models
Browse files
app.py
CHANGED
@@ -347,33 +347,33 @@ class ChatBot:
|
|
347 |
return f"Error pemrosesan file: {str(e)}"
|
348 |
|
349 |
def change_model(self, model_key):
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
|
354 |
-
|
355 |
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
|
366 |
-
|
367 |
-
|
368 |
|
369 |
-
|
370 |
-
|
371 |
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
|
378 |
def chat(self, message, history):
|
379 |
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:
|