简体   繁体   English

如何将我的 ChatBot 转换为 .js 文件以嵌入我的网站

[英]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.

相关问题 如何向我的聊天机器人添加计算器 - how do I add a calculator to my chatbot 如何从我的本地文件中获取随机图像并将其放置在 Discord.js 中的嵌入中 - How do I get a Random Image from my Local file and place it on Embed in Discord.js 我如何使用 tumblr tweets.js 文件将我的推文与附加图像一起嵌入? - how do i use the tumblr tweets.js file to embed my tweets with the attached images? 如何在我的网站上使用我的 CSV 文件中的数据? - How do i use the data in my CSV file on my website? 如何在我的网站上嵌入实时Google Analytics(分析)信息中心? - How do I embed a Real-Time Google Analytics Dashboard onto my website? 如何在我的网站中嵌入指向办公地点的 Bing 地图? - How do I embed Bing maps in my website pointing to a office location? 如何使用 JS 更新我网站上显示的单个值? - How do I update a single value displayed on my website with JS? 如何将我的 JS 文件导入到我的 HTML 文件中 - How do I import my JS file into my HTML file 如何在我的网站中嵌入 Facebook Like Box? - How can I embed a Facebook Like Box in my website? 如何将现有的播客嵌入到我的网站中? - How can I embed an existing podcast into my website?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM