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
  [split] How to convert the CSV text file into a txt file Pinto94 5 675 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  how do i store then call a mp3 from sqlite3 .db file gr3yali3n 3 935 Dec-11-2020, 10:28 AM
Last Post: snippsat
  Regex text file to store data in list TheSithSiggi 1 420 Dec-03-2020, 04:46 PM
Last Post: bowlofred
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 1,018 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  chatterbot utf-8 errors with mysql database isolatedastronaut 0 413 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 587 Sep-11-2020, 06:28 AM
Last Post: bowlofred
  Web Form to Python Script to Text File to zip file to web wfsteadman 1 739 Aug-09-2020, 02:12 PM
Last Post: snippsat
  Convert Excel file to Text file marvel_plato 6 3,757 Jul-17-2020, 01:45 PM
Last Post: marvel_plato
  How do I store the data in another txt file blacklight 1 617 Jun-26-2020, 11:09 AM
Last Post: Larz60+
  Rename file from value in text file Nuge93 1 938 Jan-20-2020, 03:50 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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