Spaces:
Sleeping
Sleeping
update indentation change_models
Browse files346 unmodified lines347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379346 unmodified linesreturn f"Error pemrosesan file: {str(e)}"def change_model(self, model_key):"""Change the model being used and recreate the chain if necessary"""if model_key == self.model_key:return f"Model {model_key} sudah digunakan."self.model_key = model_key# If we have an active session with a file already loaded, recreate the chainif self.csv_file_path:try:# Load existing databasedb_path = f"{self.user_dir}/db_faiss"embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2',model_kwargs={'device': 'cpu'})# Tambahkan flag allow_dangerous_deserialization=Truedb = FAISS.load_local(db_path, embeddings, allow_dangerous_deserialization=True)# Create new chain with the selected modelself.chain = create_conversational_chain(db, self.csv_file_path, self.model_key)return f"Model berhasil diubah ke {model_key}."except Exception as e:return f"Error mengubah model: {str(e)}"else:return f"Model diubah ke {model_key}. Silakan upload file CSV untuk memulai."def chat(self, message, history):if self.chain is None:346 unmodified lines347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379346 unmodified linesreturn f"Error pemrosesan file: {str(e)}"def change_model(self, model_key):"""Change the model being used and recreate the chain if necessary"""if model_key == self.model_key:return f"Model {model_key} sudah digunakan."self.model_key = model_key# If we have an active session with a file already loaded, recreate the chainif self.csv_file_path:try:# Load existing databasedb_path = f"{self.user_dir}/db_faiss"embeddings = HuggingFaceEmbeddings(model_name='sentence-transformers/all-MiniLM-L6-v2',model_kwargs={'device': 'cpu'})# Tambahkan flag allow_dangerous_deserialization=Truedb = FAISS.load_local(db_path, embeddings, allow_dangerous_deserialization=True)# Create new chain with the selected modelself.chain = create_conversational_chain(db, self.csv_file_path, self.model_key)return f"Model berhasil diubah ke {model_key}."except Exception as e:return f"Error mengubah model: {str(e)}"else:return f"Model diubah ke {model_key}. Silakan upload file CSV untuk memulai."def chat(self, message, history):if self.chain is None:
app.py+22-22