[英]How do I convert my ChatBot into a .js file to embed on my website
I have tried for several days to find an answer to my question but every single website says to use Django or Flask.我已经尝试了几天来找到我的问题的答案,但每个网站都说要使用 Django 或 Flask。 I don't want a server to run the code on I just want to embed it in my .HTML file as a .js.我不想让服务器在上面运行代码,我只想将它作为 .js 嵌入到我的 .HTML 文件中。 I tried using Brython but that did not work.我尝试使用 Brython 但这没有用。 I am working on windows 10 Can you please help.我正在 Windows 10 上工作,你能帮忙吗? The code is below:代码如下:
from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
import os
from tkinter import *
from tkinter import ttk
#Trains the AI
bot = ChatBot('tutor')
trainer = ListTrainer(bot)
for _file in os.listdir('txt'):
chats = open('txt/' + _file, 'r').readlines()
trainer.train(chats)
def respond(event):
re = ue.get()
res = bot.get_response(re)
be.config(state=NORMAL)
be.delete(1.0, "end")
ue.delete(0, "end")
be.insert(1.0, res)
be.config(state=DISABLED)
#t = True
#while t:
# request = input('You:')
# response = bot.get_response(request)
# print('Bot:', response)
r = Tk()
ue = Entry(r)
l = Label(r, text="")
be = Text(r, width=59, height=5)
sb = Button(r, text="Enter")
sb.bind("<Button-1>", respond)
bl = Label(r, text="Bot:")
ul = Label(r, text="User:")
sb.grid(row=0, column=3)
be.grid(row=4, column=2)
l.grid(row=3, column=2)
ue.grid(row=0, column=2)
bl.grid(row=4, column=1)
ul.grid(row=0, column=1)
r.mainloop()
It seems lie pypy.js may be the answer to your problem:似乎谎言pypy.js可能是您问题的答案:
<!-- shim for ES6 `Promise` builtin -->
<script src="./lib/Promise.min.js" type="text/javascript"></script>
<!-- shim for off-main-thread function compilation -->
<script src="./lib/FunctionPromise.js" type="text/javascript"></script>
<script src="./lib/pypyjs.js" type="text/javascript"></script>
<script type="text/javascript">
pypyjs.ready().then(function() {
pypyjs.execfile("https://www.yourwebsite.com/whatever/yourscript.py");
pypyjs.get("variable_name") //get values from python to display on the page
})
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.