ChatGPT GUI

查看 210|回复 10
作者:洛枫   
用tkinter做得chatgpt的UI,但发现其实不大好用,还不如网页版直接打包exe。
用到的库是这个:https://github.com/acheong08/ChatGPT
需要装个库:pip3 install revChatGPT==0.0.a42


image.png (30.57 KB, 下载次数: 0)
下载附件
2022-12-12 21:23 上传



image.png (39.81 KB, 下载次数: 0)
下载附件
2022-12-12 21:23 上传

同目录还需要一个“config.json”
[Asm] 纯文本查看 复制代码{
    "session_token": "",
    "cf_clearance": "",
    "user_agent": ""
}
Python代码:
[Python] 纯文本查看 复制代码
from tkinter import *
from tkinter.ttk import *
import json
# from chatgpt_wrapper import ChatGPT
# from revChatGPT.revChatGPT import Chatbot
# pip3 install revChatGPT==0.0.a42
from revChatGPT.revChatGPT import AsyncChatbot as Chatbot
import asyncio
class WinGUI(Tk):
    def __init__(self):
        super().__init__()
        self.__win()
        self.tk_button_send = self.__tk_button_send()
        self.tk_input_inputs = self.__tk_input_inputs()
        self.tk_text_show = self.__tk_text_show()
        self.tk_label_note = self.__tk_label_note()
        self.process_done = False
    def __win(self):
        self.title("ChatGPT GUI")
        # 设置窗口大小、居中
        width = 500
        height = 445
        screenwidth = self.winfo_screenwidth()
        screenheight = self.winfo_screenheight()
        geometry = '%dx%d+%d+%d' % (width, height, (screenwidth - width) / 2, (screenheight - height) / 2)
        self.geometry(geometry)
        self.resizable(width=False, height=False)
    def __tk_button_send(self):
        btn = Button(self, text="发送")
        btn.place(x=420, y=20, width=60, height=40)
        return btn
    def __tk_input_inputs(self):
        ipt = Entry(self)
        ipt.place(x=20, y=20, width=380, height=40)
        return ipt
    def __tk_text_show(self):
        text = Text(self)
        text.place(x=20, y=103, width=460, height=336)
        return text
    def __tk_label_note(self):
        label = Label(self,text="",anchor="center")
        label.place(x=20, y=70, width=460, height=24)
        return label
class Win(WinGUI):
    def __init__(self):
        super().__init__()
        self.config(menu=self.create_menu())
        self.__event_bind()
        self.chatbot = Chatbot(json.loads(open('config.json', 'r').read()), conversation_id=None)
        self.update_note('welcome!')
    def create_menu(self):
        menu = Menu(self,tearoff=False)
        return menu
   
    def update_show(self, strings):
        self.tk_text_show.delete('1.0', END)
        self.tk_text_show.insert('1.0', strings)
        self.tk_text_show.update()
   
    def update_note(self, strings):
        self.tk_label_note.config(text=strings)
   
    async def wait_for_response(self, inputs):
        self.update_show('')
        async for i in await self.chatbot.get_chat_response(inputs, output="stream"):
            print(i['message'])
            self.update_show(i['message'])
        self.process_done = True
        self.update_note('回复完成!')
    def bot_ask(self, evt):
        print("点击事件", evt)
        inputs = self.tk_input_inputs.get().strip()
        self.process_done = False
        if inputs:
            self.update_note(f'>> 输入内容为:{inputs}, 等待回复中...')
            asyncio.run(self.wait_for_response(inputs))
        else:
            self.update_note('>> 请先输入内容。')
        
        
    def __event_bind(self):
        self.tk_button_send.bind('[B]',self.bot_ask)
        
if __name__ == "__main__":
    win = Win()
    win.mainloop()

下载次数, 代码

boxer   

一个注册已经挡住99%的人
hopeallen   

请问config里面除了cookie
另外两个填入什么呀?
    "cf_clearance": "",
    "user_agent": ""
目前执行后弹出一个chrome隐私窗口,但是始终进不去页面
报错信息
Waiting for cookies...
WARNING:urllib3.connectionpool:Connection pool is full, discarding connection: localhost. Connection pool size: 1
WARNING:urllib3.connectionpool:Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')': /session/972d63ef01896c5302389e48f97c80a5/se/log
WARNING:urllib3.connectionpool:Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')': /session/972d63ef01896c5302389e48f97c80a5/se/log
Waiting for cookies...
WARNING:urllib3.connectionpool:Connection pool is full, discarding connection: localhost. Connection pool size: 1
WARNING:urllib3.connectionpool:Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError(': Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')': /session/972d63ef01896c5302389e48f97c80a5/se/log


1671034835331.jpg (165.89 KB, 下载次数: 0)
下载附件
2022-12-15 00:22 上传

paypojie   

https://chat.openai.com/chat
ChatGPT的网站页面布局非常简单 但是背后的技术是非常复杂的
paypojie   


boxer 发表于 2022-12-12 22:16
一个注册已经挡住99%的人

要不看看我的帖子 说不定有收获
https://www.52pojie.cn/thread-1724471-1-1.html
qqxiazhitmac   

感谢分享
ok667   

谢谢楼主
luffy365   

感謝樓主分享 : )
nullable   


paypojie 发表于 2022-12-12 21:57
https://chat.openai.com/chat
ChatGPT的网站页面布局非常简单 但是背后的技术是非常复杂的

有些老板看了估计又会觉得,不就是个网页吗,跟百度有什么区别(笑
嬉皮笑脸   

mark一下
您需要登录后才可以回帖 登录 | 立即注册