Viewing File: /home/ubuntu/codegamaai-test/efimarket_bot/src/training.py
import src.constants
from src.Chunk_store import *
import os
import threading
import pandas as pd
import pickle
from sklearn.feature_extraction.text import TfidfVectorizer
from src.utils import *
import requests
import json
# from mongo_main import *
import threading
import logging
log_file_path = os.path.join(os.environ['SUPPORT_BOT_DIR'], 'log','training.log')
logging.basicConfig(filename=log_file_path, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def train_and_save(user_id, bot_id):
chunk_size=1000
chunk_overlap=100
method_id="method_1"
if method_id == "method_1":
method_1(user_id,bot_id,chunk_size,chunk_overlap)
return "Training and saving will start in a separate thread."
# user_id = 69
# bot_id = 69
# train_and_save(user_id, bot_id)
# def create_vector_model(user_id,bot_id):
# dataset_path= "./Local_DB/"+str(user_id)+"/"+str(bot_id)+"/"+"q_a_data/data.csv"
# model_path= "./Local_DB/"+str(user_id)+"/"+str(bot_id)+"/"+"q_a_data/chatbot_model.pkl"
# if os.path.exists(dataset_path):
# # Read the dataset from CSV
# dataset = pd.read_csv(dataset_path)
# # Create a TF-IDF vectorizer
# vectorizer = TfidfVectorizer()
# # Fit the vectorizer on the questions
# vectorizer.fit(dataset['Question'])
# # Save the vectorizer model to a pickle file
# with open(model_path, 'wb') as file:
# pickle.dump(vectorizer, file)
# headers = {'Content-Type': 'application/json'}
# payload = {'bot_id': bot_id,'status': '2'}
# requests.post(constants.Faq_status, headers=headers, data=json.dumps(payload)).json()
# return "QandA Trained succesfully"
# else:
# headers = {'Content-Type': 'application/json'}
# payload = {'bot_id': bot_id,'status': '3'}
# requests.post(constants.Faq_status, headers=headers, data=json.dumps(payload)).json()
# return "No file in folder"
Back to Directory
File Manager