完整gpt应用(自用)

ops/2024/11/14 12:48:49/

qrc.py

gpt_qrc.qrc转化成gpt_qrc.py

pyrcc5 -o icons_rc.py icons.qrc 
<RCC><qresource prefix="img"><file>img/53.png</file><file>img/ai.png</file><file>img/关闭.png</file><file>img/最小化.png</file></qresource>
</RCC>

UI.py

# -*- coding: utf-8 -*-# Form implementation generated from reading ui file 'gpt_ui.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgetsclass Ui_Form(object):def setupUi(self, Form):Form.setObjectName("Form")Form.resize(828, 874)self.label = QtWidgets.QLabel(Form)self.label.setGeometry(QtCore.QRect(80, 180, 651, 501))self.label.setStyleSheet("\n"
"border-image: url(:/img/img/53.png);\n"
"border-radius:45px;")self.label.setObjectName("label")self.frame = QtWidgets.QFrame(Form)self.frame.setGeometry(QtCore.QRect(510, 180, 217, 52))self.frame.setStyleSheet("QPushButton{\n"
"    border:none;\n"
"}\n"
"QPushButton:hover{\n"
"    padding-bottom:5px;\n"
"}")self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)self.frame.setFrameShadow(QtWidgets.QFrame.Raised)self.frame.setObjectName("frame")self.horizontalLayout = QtWidgets.QHBoxLayout(self.frame)self.horizontalLayout.setObjectName("horizontalLayout")self.pushButton = QtWidgets.QPushButton(self.frame)self.pushButton.setText("")icon = QtGui.QIcon()icon.addPixmap(QtGui.QPixmap(":/img/img/最小化.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)self.pushButton.setIcon(icon)self.pushButton.setObjectName("pushButton")self.horizontalLayout.addWidget(self.pushButton)self.pushButton_2 = QtWidgets.QPushButton(self.frame)self.pushButton_2.setText("")icon1 = QtGui.QIcon()icon1.addPixmap(QtGui.QPixmap(":/img/img/关闭.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)self.pushButton_2.setIcon(icon1)self.pushButton_2.setObjectName("pushButton_2")self.horizontalLayout.addWidget(self.pushButton_2)self.lineEdit = QtWidgets.QLineEdit(Form)self.lineEdit.setGeometry(QtCore.QRect(206, 590, 391, 51))font = QtGui.QFont()font.setFamily("微软雅黑")font.setPointSize(10)self.lineEdit.setFont(font)self.lineEdit.setStyleSheet("border:none;\n"
"border:2px solid rgb(0,0,0);\n"
"border-radius:5px;\n"
"background:transparent;")self.lineEdit.setText("")self.lineEdit.setObjectName("lineEdit")self.pushButton_3 = QtWidgets.QPushButton(Form)self.pushButton_3.setGeometry(QtCore.QRect(614, 583, 55, 65))self.pushButton_3.setStyleSheet("QPushButton{\n"
"    border:none;\n"
"}\n"
"QPushButton:hover{\n"
"    padding-bottom:5px;\n"
"}")self.pushButton_3.setText("")icon2 = QtGui.QIcon()icon2.addPixmap(QtGui.QPixmap(":/img/img/ai.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)self.pushButton_3.setIcon(icon2)self.pushButton_3.setIconSize(QtCore.QSize(50, 50))self.pushButton_3.setObjectName("pushButton_3")self.textBrowser = QtWidgets.QTextBrowser(Form)self.textBrowser.setGeometry(QtCore.QRect(170, 250, 491, 291))font = QtGui.QFont()font.setFamily("幼圆")font.setPointSize(12)self.textBrowser.setFont(font)self.textBrowser.setStyleSheet("background:transparent; border:none; border - style:outset")self.textBrowser.setObjectName("textBrowser")self.comboBox = QtWidgets.QComboBox(Form)self.comboBox.setGeometry(QtCore.QRect(130, 590, 71, 22))self.comboBox.setStyleSheet("background:transparent;")self.comboBox.setObjectName("comboBox")self.comboBox_2 = QtWidgets.QComboBox(Form)self.comboBox_2.setGeometry(QtCore.QRect(130, 620, 71, 22))self.comboBox_2.setStyleSheet("background:transparent;")self.comboBox_2.setObjectName("comboBox_2")self.retranslateUi(Form)self.pushButton.clicked.connect(Form.showMinimized) # type: ignoreself.pushButton_2.clicked.connect(Form.close) # type: ignoreQtCore.QMetaObject.connectSlotsByName(Form)def retranslateUi(self, Form):_translate = QtCore.QCoreApplication.translateForm.setWindowTitle(_translate("Form", "顾某"))self.label.setText(_translate("Form", "、"))self.lineEdit.setPlaceholderText(_translate("Form", "输入问题:"))

应用

#该程序不会保存语音文件,在线播放
import requests,os,io
from gpt_ui import Ui_Form   #UI
import sys
from PyQt5 import QtGui
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import Qt, QPoint, QThread,pyqtSignal
import gpt_qrc     #qrc生成的py #样式表
from pygame import mixer
import pygame.mixer
#设置任务栏
import ctypes
import hashlib  #用于生成sign
import time
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID("com.example.myapp")
pygame.mixer.init()  # 语音初始化
#子线程下载
class MyThread(QThread):name_received = pyqtSignal(str)       # 定义信号,传递 str 类型的参数def __init__(self,ai,s,voice):super().__init__()#生成signself.timestamp = str(int(time.time() * 1000))  # 将时间戳转换为毫秒public_secret_key = ""# 构造签名字符串signature_string = f"{self.timestamp}:{s}:{public_secret_key}"hash_object = hashlib.sha256(signature_string.encode('utf-8'))# 获取十六进制形式的哈希值   hash_hexself.sign = hash_object.hexdigest()self.url0 = 'http://api.ztk1.cn/API/Chat3.5.php?msg=' + s + '&id=1&type=1'   #gptmini# self.url0 = 'https://api.lolimi.cn/API/AI/gpt4o.php?sx=&msg=' +s                   #回答网址参数self.url1 = 'https://api.zrzh.asia/api/ChatGPT.php?message='+s+'&id=10001'self.url2 = 'http://api.xyovo.top/API/ChatGPT.php?message='+s+'&id=123&type=text'self.url3= 'https://claude3.free2gpt.xyz/api/generate'self.ai = aiself.data3 ={"messages": [{"role": "user","content": s}],"time": self.timestamp,"sign": self.sign}# self.voice_url = 'https://api.lolimi.cn/API/yyhc/'+voice+'.php?msg='   #语音合成网址# shengyin=https://api.yujn.cn/api/yuyin.php?type=json&from=丁真&msg=我测尼玛self.voice_url = f'https://api.yujn.cn/api/yuyin.php?type=json&from={voice}&msg='   #语音合成网址# self.voice = voicedef run(self):try:if self.ai==0:message = requests.post(self.url0).json().get('data').get('content')#dwai 0125elif self.ai==1:message = requests.post(self.url1).json().get('data').get('content')#dwai 0125elif self.ai==2:message = requests.get(self.url2).textelif self.ai==3:message = requests.get(self.url3,json=self.data3).text    #api 4.0self.name_received.emit(message)print(message)# #判断 message 的长度是否小于30# if len(message) < 20:#     try:#         # voice_url = f'https://api.yujn.cn/api/yuyin.php?type=json&from={voice}&msg={message}'#         voice_url = self.voice_url + message#         audio_response = requests.get(voice_url)  # 请求音频#         if audio_response.status_code == 200:#             # 将音频数据包装成类文件对象(BytesIO对象)#             audio_data = io.BytesIO(audio_response.content)#             # 加载音频数据并播放#             pygame.mixer.music.load(audio_data)#             pygame.mixer.music.play()#             self.name_received.emit(message)#             # 等待音乐播放完毕#             while pygame.mixer.music.get_busy():#                 pygame.time.Clock().tick(10)#         else:#             self.name_received.emit(message)#             print('音频文件请求失败')#     except Exception as e:#         self.name_received.emit(message)#         print("播放失败")# else:#     self.name_received.emit(message)except Exception as e:self.name_received.emit(f'请求错误: {str(e)}')
class guWindow(QWidget):def __init__(self):super().__init__()self.gu = Ui_Form()self.gu.setupUi(self)comboBox = self.gu.comboBoxcomboBox.addItem("懒羊羊")comboBox.addItem("科比")comboBox.addItem("丁真")comboBox.addItem("陈泽")comboBox1=self.gu.comboBox_2# 添加下拉框选项comboBox1.addItem("1")comboBox1.addItem("2")comboBox1.addItem("3")comboBox1.addItem("4")an = self.gu.pushButton_3  # 按钮self.gu.lineEdit.returnPressed.connect(self.gumou)    #lineEdit回车运行an.clicked.connect(self.gumou)  # 给按钮绑定函数self.user_name_qwidget = self.gu.lineEdit# ✦✦✦✦✦✦✦✦✦✦设置无边框 和可拖动✦✦✦✦✦✦✦✦✦✦✦✦✦固定代码self.setWindowOpacity(0.90)  # 设置窗口透明度self.setWindowFlag(Qt.FramelessWindowHint)  # 去除边框self.setAttribute(Qt.WA_TranslucentBackground)  # 去除白色背景self.offset = QPoint()     # 记录鼠标按下的初始位置def mousePressEvent(self, event):self.offset = event.pos()def mouseMoveEvent(self, event):if event.buttons() == Qt.LeftButton:self.move(self.pos() + event.pos() - self.offset)    # 移动窗口位置def gumou(self):  # 按钮绑定的函数 功能s = self.user_name_qwidget.text()self.user_name_qwidget.clear()index = self.gu.comboBox.currentIndex()   #下拉框选择器if index == 0:voice = "懒羊羊"elif index == 1:voice = "科比"elif index == 2:voice = "丁真"elif index == 3:voice = "陈泽"ai = self.gu.comboBox_2.currentIndex()  # 下拉框选择器if ai == 0:ai=0elif ai == 1:ai=1elif ai == 2:ai=2elif ai == 3:ai=3self.my_thread = MyThread(ai,s,voice)  # 创建线程self.my_thread.name_received.connect(self.receive_name)  # 连接信号self.my_thread.start()  # 开始线程self.gu.textBrowser.clear()self.gu.textBrowser.append("提问:"+s)def receive_name(self, name):    #接收nameself.gu.textBrowser.append('\n'+name)
if __name__ == '__main__':app = QApplication(sys.argv)icon = QtGui.QIcon(':/img/img/ai.png')app.setWindowIcon(icon)# 创建可拖动窗口实例ui = guWindow()        #函数# 显示窗口ui.show()# 启动应用程序事件循环sys.exit(app.exec_())

上述所需图片


http://www.ppmy.cn/ops/113104.html

相关文章

网络安全学习路线,史上最全网络安全学习路线整理

很多小伙伴在网上搜索网络安全时&#xff0c;会出来网络安全工程师这样一个职位&#xff0c;它的范围很广&#xff0c;只要是与网络安全挂钩的技术人员都算网络安全工程师&#xff0c;一些小伙伴就有疑问了&#xff0c;网络安全现在真的很火吗&#xff1f; 那么无涯就带大家看…

PG表空间

目录标题 PG表空间PostgreSQL表空间的最佳实践是什么&#xff1f;如何在PostgreSQL中创建和管理自定义表空间&#xff1f;PostgreSQL表空间对数据库性能的具体影响有哪些&#xff1f;在PostgreSQL中&#xff0c;如何迁移数据到不同的表空间以优化存储布局&#xff1f;PostgreSQ…

IM项目-----语音识别子服务

提示&#xff1a;文章写完后&#xff0c;目录可以自动生成&#xff0c;如何生成可参考右边的帮助文档 文章目录 前言一、搭建思想二、服务器搭建1.继承speechService类,重写业务代码2.编写语音识别服务器类3.建造者类编写 三.测试 前言 语音转换子服务&#xff0c;用于调用语音…

【深入浅出Redis】Redis常见问题以及解决方案,可用于面试

前面分享了几篇Redis系列文章&#xff0c;那么我们在使用Redis的过程中都会遇到什么问题&#xff1f;如何解决&#xff1f;都有哪些方案&#xff1f; 下面给大家介绍下 redis系列问题以及优化 Redis-hotkey热key 大量请求可能会使redis宕机&#xff0c;继而打到数据库崩溃&am…

安全通信网络等保

通用要求 1.网络架构 1)应保证网络设备的业务处理能力满足业务高峰期需要。 设备CPU和内存使用率的峰值不大于设备处理能力的70%。 在有监控环境的条件下,应通过监控平台查看主要设备在业务高峰期的资源(CPU、内存等)使用 情况;在无监控环境的情况下,在业务高峰期登录…

Istio:微服务网格的强大工具,Istio介绍

什么是Istio&#xff1f; 在现代软件开发中&#xff0c;微服务架构已经成为构建可扩展、灵活系统的首选方法。然而&#xff0c;随着微服务数量的增加&#xff0c;服务间的通信、监控和管理变得越来越复杂。为了解决这些问题&#xff0c;服务网格&#xff08;Service Mesh&…

AD覆铜,过孔全连接,焊盘十字连接

本处以AD16描述。PCB环境下&#xff0c;快捷键“DR”或Design→Rules→Plane→Polygon Connect style。 过孔与焊盘共有三种连接方式&#xff1a;Relief Connect(十字连接)、Direct Connect(全连接)和No Connect(不连接)&#xff0c;如图1.1所示。 图1.1 三种连接方式 若所有…

K8s 之Pod的定义及详细资源调用案例

资源管理介绍 在kubernetes中&#xff0c;所有的内容都抽象为资源&#xff0c;用户需要通过操作资源来管理kubernetes。kubernetes的本质上就是一个集群系统&#xff0c;用户可以在集群中部署各种服务所谓的部署服务&#xff0c;其实就是在kubernetes集群中运行一个个的容器&a…