From 24c9a1ff58627e229a1b2e74f5e41962b170cfed Mon Sep 17 00:00:00 2001 From: Sonny Li Date: Wed, 23 Dec 2020 15:24:50 -0500 Subject: [PATCH] move to single file --- app/database.sqlite3 | Bin 245760 -> 335872 bytes app/main.py | 131 ++++++++++++++++++++++- app/scripts/chatbot.py | 228 ++++++++++++++++++++--------------------- 3 files changed, 242 insertions(+), 117 deletions(-) diff --git a/app/database.sqlite3 b/app/database.sqlite3 index 8ce42377542efa044f8479577bbc7117f5bf57dc..15f6bdd5eceb6f1850b7b38b7b75908358886ed1 100644 GIT binary patch delta 7498 zcmZvh3vd+2na9<=i+M>aY#bcGLJ|*y4UxNNdZv2>2nn!xn1_UUnwNwD3lK;O;w7Fd zZ+9v-t}~gKwsTHmE_ZhB;so&8Y@7grRC10FY=^TQ*Foh{zPluqi<65h$)$1^*WI@> zJ+rge6tt-RcYo85@B6xctz*Zkk6pU`$+3fmRa8_gJ5e_a4LjTZxAzWNl$iq+70die z(lsq}IrH7jE1A=ozt4Ov^W}`roX9+$k(r~J1DV~KotZ~69htS66`7@(1(`YdTSxp& z)zLP!33|7xbxm204!BbP%tTP}dIMK(g&EG;N!$$Ow|lJ!u|l$B7DYq+s>US5hzSNPb zEOh2mPgkC7$KS-V@~JcEtZwhXgDOKSw&hZX=-v)ohvo2-Z=o3(r_o5%qpqj_6(NG< zFg*gJ`DHz+5R~at7)?!QGjgckwrs9GwjJLRS*F6VxTX(dk=iGR`0p=k3*?EBbzxI$ zUuSpS&W_Dn>JD`8nYF65vH1V&AvsuIIg9MXNF3K?`g9t7H$8ymE&9q!=z2*doY_L3 z-GaxYcE~~c$9cqK(egNPY+ZK?x+~Q#)4J(pG^Z|_q2)P_;C-DPyLJ=@uw+Rilm}%> zpL!WhOPH`MmRrSeLu!OLM(5D{36R@n% zzkLPGDt%rE;#!*yY$^URKeCm%qk8cJ!`X zi#XS>n}?$xCO6-5ZAxta(%LaNcR~UL1FXaS+OVdSj%n9f`(a zS*K_1#!G`>Wev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?pVBX~SxEM!F08Zlxh!5QGhjHs3-7%|ix*kt$7O0^`xh(;0c02DH! zTAXCWNG9-{7%-w*WEjyX00I1vdLY4wk>G;g7)DeJV@4bn9_Ef?!+#w5HadY zEw)$94-he0KX`=l{6iO)U^Op6h^7NPP%j6KvMwso!ty@;?{VF)qoA~-xC zsI_YO&4d_r6`a6h)Uh8n0K`0`9*iK-^oI0G0!UQL5|9{*9Nxd#@sw&akZ5W-y!9j? zQLRftV$jAV9uRjKB&xLr5>12RYqvb29*QB+tfxze$p87BcQICLl89)!5xC_TL{zI2 zh!_sdV-6(8Dzz$sh(-ZUazjK^DIei%U^NM71%2h(?FEM>bV$NFZV;5KmAqw^ywaG%pF delta 82 zcmZoTAkxslKS7$6gMop;W}<>UBge*sCHfp@e8+(T3^tQ_401LL3Iy>rpR#K|Wyc7_ lOxsV{F
+ In OOP, computer programs are designed by making them out of objects that interact with one another.\n\n + + Sonny: What is a Where in SQL?\n + Codey: WHERE is used to filter rows.

+ SELECT column1, column2, ...
+ FROM table_name
+ WHERE column1 = value1;\n\n + + Sonny: What is a Subquery in SQL?\n + Codey: A subquery is a SQL query nested inside another SQL query.

+ SELECT column1, column2, ...
+ FROM table_name
+ WHERE column1 IN (SELECT column1 FROM table_name);\n\n + + Sonny: {} + Codey:""".format(question) + + response = openai.Completion.create( + engine="davinci", + prompt=prompt, + stop="Sonny:", + temperature=0.6, + max_tokens=150, + top_p=1, + presence_penalty=0.3, + ) + print(response) + json_response = json.dumps(response) + rep = json.loads(json_response) + bot_reply = rep['choices'][0]['text'] + print(question) + print(str(bot_reply)) + return str(bot_reply) + + app = Flask(__name__) app.static_folder = 'static' + @app.route("/") def home(): return render_template("index.html") diff --git a/app/scripts/chatbot.py b/app/scripts/chatbot.py index b713e3e..cd480d6 100644 --- a/app/scripts/chatbot.py +++ b/app/scripts/chatbot.py @@ -1,122 +1,122 @@ -import config - -from chatterbot import ChatBot -from chatterbot.trainers import ListTrainer -from chatterbot.trainers import ChatterBotCorpusTrainer - -import json -import openai - -# Creating ChatBot Instance -cs_chatbot = ChatBot( - 'CoronaBot', - storage_adapter='chatterbot.storage.SQLStorageAdapter', - logic_adapters=[ - 'chatterbot.logic.MathematicalEvaluation', - 'chatterbot.logic.TimeLogicAdapter', - 'chatterbot.logic.BestMatch', - { - 'import_path': 'chatterbot.logic.BestMatch', - 'default_response': 'I am sorry, but I do not understand. I am still learning.', - 'maximum_similarity_threshold': 0.90 - } - ], - database_uri='sqlite:///database.sqlite3' -) - - # Training with Personal Ques & Ans -training_data_simple = open('../training_data/normal.txt').read().splitlines() -training_data_personal = open('../training_data/all.txt').read().splitlines() - -training_data = training_data_simple + training_data_personal - -trainer = ListTrainer(cs_chatbot) -trainer.train(training_data) - -# Training with English Corpus Data -trainer_corpus = ChatterBotCorpusTrainer(cs_chatbot) - - -# chatbot.py Camelia - -openai.api_key = config.api_key #os.getenv("API_KEY") - -def gpt_chatbot(question): - - # prompt = """Codey is Codecademy's AI assistant and knows everything there is to know about programming. - # Codey wants to help our learners with all kinds of questions and provide them detailed answers to any questions that they ask. - # The assistant is helpful, creative, clever, very friendly, and very encouraging. - - # Sonny: What is HTML?\nCodey: HTML (HyperText Markup Language) is the main building block of websites and webpages. It is used to specify the layout and content of a webpage, and makes it possible for a browser to read and display it. And it can be assisted by technologies such as Cascading Style Sheets and scripting languages such as JavaScript.\n\n - # Sonny: What is while loop?\nCodey: \nA while loop is a control flow structure that repeats a statement or group of statements until a certain condition becomes false. The condition is checked before the control flow enters the loop. This helps control the program flow.\n\n - # Sonny: What is a variable?\nCodey: A variable is a named memory location used to store data. This data can be of different data types.\n\n - # Sonny: What is the difference between HTML and CSS?\nCodey: HTML stands for Hypertext Markup Language, and CSS stands for Cascading Style Sheets. HTML and CSS are both used to define the look and layout of a website. HTML is used to define the content and structure of a web page, while CSS is used to change the appearance of a page.\n\n - # Sonny: What is coding?\nCodey: Coding is the process of writing computer programs. The program code is written in a programming language, and the program is compiled into a program that can be run by the CPU.\n\n - # Sonny: What is the difference between if and if else statement?\nCodey: The `if` statement is used to make a decision. If a certain condition is true, then the statement(s) following `if` is executed. If the condition is not true, then the code following the `else` statement is executed.\n\n - # Sonny: What is Object-oriented programming?\nCodey: Object-oriented programming (OOP) is a programming paradigm based on the concept of \"objects\", which might contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of `this` or `self`). In OOP, computer programs are designed by making them out of objects that interact with one another.\n\n - # Sonny: What is polymorphism?\nCodey: Polymorphism is the provision of a single interface to entities of different types.\n\n - # Sonny: Give me an example of a if statement in Python.\nCodey: if coffee == \"hot\"\n # Code runs if true\nelse:\n # Code runs if false\n\n - # Sonny: How do I write a function in JavaScript?\nCodey: \nfunction addNumbers(a, b) {\n return a + b;\n}\n\n - # Sonny: What is distinct in sql?\nCodey: Distinct is used to remove duplicate rows from a result set.\nSELECT DISTINCT column1, column2, ...\nFROM table_name;\n\n - # Sonny: What is a Where in SQL?\nCodey: WHERE is used to filter rows.\nSELECT column1, column2, ...\nFROM table_name\nWHERE column1 = value1;\n\n - # Sonny: What is a Subquery in SQL?\nCodey: A subquery is a SQL query nested inside another SQL query. \nSELECT column1, column2, ...\nFROM table_name\nWHERE column1 IN (SELECT column1 FROM table_name);\n\n - # Sonny: {} - # Codey:""".format(question) - - prompt = """Codey is Codecademy's AI assistant and knows everything there is to know about programming. - Codey wants to help our learners with all kinds of questions and provide them detailed answers to any questions - that they ask. The assistant is helpful, creative, clever, very friendly, and very encouraging. +# import config + +# from chatterbot import ChatBot +# from chatterbot.trainers import ListTrainer +# from chatterbot.trainers import ChatterBotCorpusTrainer + +# import json +# import openai + +# # Creating ChatBot Instance +# cs_chatbot = ChatBot( +# 'CoronaBot', +# storage_adapter='chatterbot.storage.SQLStorageAdapter', +# logic_adapters=[ +# 'chatterbot.logic.MathematicalEvaluation', +# 'chatterbot.logic.TimeLogicAdapter', +# 'chatterbot.logic.BestMatch', +# { +# 'import_path': 'chatterbot.logic.BestMatch', +# 'default_response': 'I am sorry, but I do not understand. I am still learning.', +# 'maximum_similarity_threshold': 0.90 +# } +# ], +# database_uri='sqlite:///database.sqlite3' +# ) + +# # Training with Personal Ques & Ans +# training_data_simple = open('../training_data/normal.txt').read().splitlines() +# training_data_personal = open('../training_data/all.txt').read().splitlines() + +# training_data = training_data_simple + training_data_personal + +# trainer = ListTrainer(cs_chatbot) +# trainer.train(training_data) + +# # Training with English Corpus Data +# trainer_corpus = ChatterBotCorpusTrainer(cs_chatbot) + + +# # chatbot.py Camelia + +# openai.api_key = config.api_key #os.getenv("API_KEY") + +# def gpt_chatbot(question): + +# # prompt = """Codey is Codecademy's AI assistant and knows everything there is to know about programming. +# # Codey wants to help our learners with all kinds of questions and provide them detailed answers to any questions that they ask. +# # The assistant is helpful, creative, clever, very friendly, and very encouraging. + +# # Sonny: What is HTML?\nCodey: HTML (HyperText Markup Language) is the main building block of websites and webpages. It is used to specify the layout and content of a webpage, and makes it possible for a browser to read and display it. And it can be assisted by technologies such as Cascading Style Sheets and scripting languages such as JavaScript.\n\n +# # Sonny: What is while loop?\nCodey: \nA while loop is a control flow structure that repeats a statement or group of statements until a certain condition becomes false. The condition is checked before the control flow enters the loop. This helps control the program flow.\n\n +# # Sonny: What is a variable?\nCodey: A variable is a named memory location used to store data. This data can be of different data types.\n\n +# # Sonny: What is the difference between HTML and CSS?\nCodey: HTML stands for Hypertext Markup Language, and CSS stands for Cascading Style Sheets. HTML and CSS are both used to define the look and layout of a website. HTML is used to define the content and structure of a web page, while CSS is used to change the appearance of a page.\n\n +# # Sonny: What is coding?\nCodey: Coding is the process of writing computer programs. The program code is written in a programming language, and the program is compiled into a program that can be run by the CPU.\n\n +# # Sonny: What is the difference between if and if else statement?\nCodey: The `if` statement is used to make a decision. If a certain condition is true, then the statement(s) following `if` is executed. If the condition is not true, then the code following the `else` statement is executed.\n\n +# # Sonny: What is Object-oriented programming?\nCodey: Object-oriented programming (OOP) is a programming paradigm based on the concept of \"objects\", which might contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of `this` or `self`). In OOP, computer programs are designed by making them out of objects that interact with one another.\n\n +# # Sonny: What is polymorphism?\nCodey: Polymorphism is the provision of a single interface to entities of different types.\n\n +# # Sonny: Give me an example of a if statement in Python.\nCodey: if coffee == \"hot\"\n # Code runs if true\nelse:\n # Code runs if false\n\n +# # Sonny: How do I write a function in JavaScript?\nCodey: \nfunction addNumbers(a, b) {\n return a + b;\n}\n\n +# # Sonny: What is distinct in sql?\nCodey: Distinct is used to remove duplicate rows from a result set.\nSELECT DISTINCT column1, column2, ...\nFROM table_name;\n\n +# # Sonny: What is a Where in SQL?\nCodey: WHERE is used to filter rows.\nSELECT column1, column2, ...\nFROM table_name\nWHERE column1 = value1;\n\n +# # Sonny: What is a Subquery in SQL?\nCodey: A subquery is a SQL query nested inside another SQL query. \nSELECT column1, column2, ...\nFROM table_name\nWHERE column1 IN (SELECT column1 FROM table_name);\n\n +# # Sonny: {} +# # Codey:""".format(question) + +# prompt = """Codey is Codecademy's AI assistant and knows everything there is to know about programming. +# Codey wants to help our learners with all kinds of questions and provide them detailed answers to any questions +# that they ask. The assistant is helpful, creative, clever, very friendly, and very encouraging. - Sonny: What is HTML?\n - Codey: HTML (HyperText Markup Language) is the main building block of websites and webpages. It is used to specify the layout and content of a webpage, and makes it possible for a browser to read and display it. And it can be assisted by technologies such as Cascading Style Sheets and scripting languages such as JavaScript.\n\n +# Sonny: What is HTML?\n +# Codey: HTML (HyperText Markup Language) is the main building block of websites and webpages. It is used to specify the layout and content of a webpage, and makes it possible for a browser to read and display it. And it can be assisted by technologies such as Cascading Style Sheets and scripting languages such as JavaScript.\n\n - Sonny: What is while loop?\n - Codey: \nA `while` loop is a control flow structure that repeats a statement or group of statements until a certain condition becomes false. The condition is checked before the control flow enters the loop. This helps control the program flow.\n\n +# Sonny: What is while loop?\n +# Codey: \nA `while` loop is a control flow structure that repeats a statement or group of statements until a certain condition becomes false. The condition is checked before the control flow enters the loop. This helps control the program flow.\n\n - Sonny: What is a variable?\n - Codey: A variable is a named memory location used to store data. This data can be of different data types.\n\n +# Sonny: What is a variable?\n +# Codey: A variable is a named memory location used to store data. This data can be of different data types.\n\n - Sonny: What is the difference between HTML and CSS?\n - Codey: HTML stands for Hypertext Markup Language, and CSS stands for Cascading Style Sheets. HTML and CSS are both used to define the look and layout of a website. HTML is used to define the content and structure of a web page, while CSS is used to change the appearance of a page.\n\n +# Sonny: What is the difference between HTML and CSS?\n +# Codey: HTML stands for Hypertext Markup Language, and CSS stands for Cascading Style Sheets. HTML and CSS are both used to define the look and layout of a website. HTML is used to define the content and structure of a web page, while CSS is used to change the appearance of a page.\n\n - Sonny: What is coding?\n - Codey: Coding is the process of writing computer programs. The program code is written in a programming language, and the program is compiled into a program that can be run by the CPU.\n\n +# Sonny: What is coding?\n +# Codey: Coding is the process of writing computer programs. The program code is written in a programming language, and the program is compiled into a program that can be run by the CPU.\n\n - Sonny: What is the difference between if and if else statement?\n - Codey: The `if` statement is used to make a decision. If a certain condition is true, then the statement(s) following `if` is executed. If the condition is not true, then the code following the `else` statement is executed. The `else` statement is optional.\n\n +# Sonny: What is the difference between if and if else statement?\n +# Codey: The `if` statement is used to make a decision. If a certain condition is true, then the statement(s) following `if` is executed. If the condition is not true, then the code following the `else` statement is executed. The `else` statement is optional.\n\n - Sonny: What is object-oriented programming?\n - Codey: Object-oriented programming (OOP) is a programming paradigm based on the concept of \"objects\", which might contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of `this` or `self`).

- In OOP, computer programs are designed by making them out of objects that interact with one another.\n\n +# Sonny: What is object-oriented programming?\n +# Codey: Object-oriented programming (OOP) is a programming paradigm based on the concept of \"objects\", which might contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. A feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated (objects have a notion of `this` or `self`).

+# In OOP, computer programs are designed by making them out of objects that interact with one another.\n\n - Sonny: What is a Where in SQL?\n - Codey: WHERE is used to filter rows.

- SELECT column1, column2, ...
- FROM table_name
- WHERE column1 = value1;\n\n - - Sonny: What is a Subquery in SQL?\n - Codey: A subquery is a SQL query nested inside another SQL query.

- SELECT column1, column2, ...
- FROM table_name
- WHERE column1 IN (SELECT column1 FROM table_name);\n\n - - Sonny: {} - Codey:""".format(question) - - response = openai.Completion.create( - engine="davinci", - prompt=prompt, - stop="Sonny:", - temperature=0.6, - max_tokens=150, - top_p=1, - presence_penalty=0.3, - ) - print(response) - json_response = json.dumps(response) - rep = json.loads(json_response) - bot_reply = rep['choices'][0]['text'] - print(question) - print(str(bot_reply)) - return str(bot_reply) \ No newline at end of file +# Sonny: What is a Where in SQL?\n +# Codey: WHERE is used to filter rows.

+# SELECT column1, column2, ...
+# FROM table_name
+# WHERE column1 = value1;\n\n + +# Sonny: What is a Subquery in SQL?\n +# Codey: A subquery is a SQL query nested inside another SQL query.

+# SELECT column1, column2, ...
+# FROM table_name
+# WHERE column1 IN (SELECT column1 FROM table_name);\n\n + +# Sonny: {} +# Codey:""".format(question) + +# response = openai.Completion.create( +# engine="davinci", +# prompt=prompt, +# stop="Sonny:", +# temperature=0.6, +# max_tokens=150, +# top_p=1, +# presence_penalty=0.3, +# ) +# print(response) +# json_response = json.dumps(response) +# rep = json.loads(json_response) +# bot_reply = rep['choices'][0]['text'] +# print(question) +# print(str(bot_reply)) +# return str(bot_reply) \ No newline at end of file