Python Forum
ChatterBot: How to store unanswered question in a text file?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ChatterBot: How to store unanswered question in a text file?
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,067 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,580 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,843 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,256 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  how do i store then call a mp3 from sqlite3 .db file gr3yali3n 3 5,635 Dec-11-2020, 10:28 AM
Last Post: snippsat
  Regex text file to store data in list TheSithSiggi 1 1,501 Dec-03-2020, 04:46 PM
Last Post: bowlofred
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,329 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  chatterbot utf-8 errors with mysql database isolatedastronaut 0 1,545 Nov-08-2020, 06:54 AM
Last Post: isolatedastronaut
  saving data from text file to CSV file in python having delimiter as space K11 1 2,356 Sep-11-2020, 06:28 AM
Last Post: bowlofred
  Web Form to Python Script to Text File to zip file to web wfsteadman 1 2,099 Aug-09-2020, 02:12 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020