Python Forum

Full Version: ChatterBot: How to store unanswered question in a text file?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, how do i store an unanswered question in chatterbot? I have a here a code for my file, but it wont store in my text file. Cry

app.py
from chatbot import chatbot
from flask import Flask, render_template, request

app = Flask(__name__)
app.static_folder = 'static'

@app.route("/")
def home():
    return render_template("index.html")

@app.route("/get")
def get_bot_response():
    userText = request.args.get('msg')
    return str(chatbot.get_response(userText))
    
    with open("data/unanswered.txt", "a") as f:
        if str(chatbot.get_response(userText)) == "I am sorry, but I do not understand. I am still learning.":
            f.write(userText)

if __name__ == "__main__":
    app.run()
chatbot.py
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import json

# Creating ChatBot Instance
chatbot = ChatBot(
    'Maruko',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    preprocessor = [
        'chatterbot.preprocessors.clean_whitespace',
    ],
    logic_adapters = [
        {
            'import_path': 'chatterbot.logic.BestMatch',
            'default_response': 'I am sorry, but I do not understand. I am still learning.',
            'maximum_similarity_threshold': 0.90
        },
        'chatterbot.logic.MathematicalEvaluation'
    ],
    database_uri = 'sqlite:///database.sqlite3',
    read_only = True
)

# Data from Data Folder
data = json.loads(open('data/nfL6.json', 'r').read())

train = []

for k, row in enumerate(data):
    train.append(row['question'])
    train.append(row['answer'])

trainer = ListTrainer(chatbot)

trainer.train(train[:1024])
Thank you! Confused