完整gpt应用(自用)

devtools/2024/9/19 21:18:28/ 标签: gpt

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/devtools/114267.html

相关文章

物联网之Arduino编程语言、条件语句、循环语句、变量、数组、函数

MENU 注释变量条件语句if语句switch语句 循环语句for循环while循环 数组函数函数基本介绍常用函数介绍 总结 注释 当编写代码时&#xff0c;注释(comments)非常重要。注释是对代码的解释和说明&#xff0c;且对于其他开发者或者自己日后需要修改代码的时候&#xff0c;都非常有…

【代码】使用c#实现串口通信的基础模板

一、分享代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;using System.IO.Ports; using…

强制转换数据类型

1.转换为String 强制类型转换 指将一个数据类型强制转换为其它数据类型 类型转换主要指&#xff0c;将其它数据类型转换为 String Number Boolean 将其他数据类型转换为String 方法一&#xff1a; 调用被转换数据类型的toString()方法; 该方法不会影响到原变量&#…

信刻光盘安全隔离与信息交换系统

随着各种数据传输、储存技术、信息技术的快速发展&#xff0c;保护信息安全是重中之重。军工、政府、部队及企事业单位等利用A网与B网开展相关工作已成为不可逆转的趋势。针对于业务需要与保密规范相关要求&#xff0c;涉及重要秘密信息&#xff0c;需做到安全的物理隔离&#…

高中数学:立体几何-平面的定义与公理

文章目录 一、平面定义及画法1、定义2、表示方法 二、公理1、公理12、公理23、公理3 一、平面定义及画法 1、定义 平面是向四周无限延展的。 2、表示方法 我们常用矩形的直观图&#xff0c;即平行四边形表示平面&#xff0e; 我们常用希腊字母α&#xff0c;β&#xff0c…

mqtt 应用场景(gpt4)

MQTT&#xff08;Message Queuing Telemetry Transport&#xff09;是一种轻量级的消息发布/订阅协议&#xff0c;主要设计用于低带宽、不可靠或不稳定的网络环境。它具有高效的带宽利用率和较低的延迟&#xff0c;特别适合物联网&#xff08;IoT&#xff09;等需要远程监控、数…

内存dump文件分析

目录 dumpsneak攻击步骤&#xff1a; dump 打开Volatility工具目录&#xff0c;C:\Users\Administrator\Desktop\应急工具集\volatility 打开运行输入volatility.exe -f 文件 imageinfo&#xff08;花费比较长的时间&#xff0c;对于这个mem文件&#xff0c;可以使用Win2012…

Android AlertDialog圆角背景不生效的问题

一行解决: window?.setBackgroundDrawableResource(android.R.color.transparent) 原文件: /*** Created by Xinghai.Zhao* 自定义选择弹框*/ SuppressLint("InflateParams", "MissingInflatedId") class CustomDialog(context: Context?) : AlertDia…

Mini-Omni:语言模型可以在流中听、说和思考

读论文《Mini-Omni: Language Models Can Hear, Talk While Thinking in Streaming》 目前比较火的一篇论文&#xff0c;分享给大家 论文地址&#xff1a;2408.16725v2 (arxiv.org) 项目地址&#xff1a;https://github.com/gpt-omni/mini-omni 1. 引言 近年来&#xff0c…

【mysql面试题】mysql复习之常见面试题(一)

本站以分享各种运维经验和运维所需要的技能为主 《python零基础入门》&#xff1a;python零基础入门学习 《python运维脚本》&#xff1a; python运维脚本实践 《shell》&#xff1a;shell学习 《terraform》持续更新中&#xff1a;terraform_Aws学习零基础入门到最佳实战 《k8…

如何在微信小程序中实现WebSocket连接

微信小程序作为一种全新的应用形态&#xff0c;凭借其便捷性、易用性受到了广大用户的喜爱。在实际开发过程中&#xff0c;实时通信功能是很多小程序必备的需求。WebSocket作为一种在单个TCP连接上进行全双工通信的协议&#xff0c;能够实现客户端与服务器之间的实时通信。本文…

Openssl升级

1、下载 openssl openssl官方下载地址&#xff1a;https://www.openssl.org/source/ [rootlocalhost ~]# wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1d.tar.gz 2、编译安装 [rootlocalhost ~]# ./config --prefix/usr/local/openssl // 指定安装路径 …

如何切换淘宝最新镜像源(npm)【2024版】

在使用 Node.js 和 npm 进行开发时&#xff0c;大家通常会遇到 npm 源速度较慢的问题。特别是当你需要安装大量依赖时&#xff0c;npm 官方源的速度可能不尽如人意。幸运的是&#xff0c;淘宝提供了一个更快速的 npm 镜像源&#xff0c;可以让你更快地下载和安装包。本文将介绍…

保护您的隐私:隐藏 IP 地址的重要性

在当今的数字时代&#xff0c;我们的在线隐私和安全变得比以往任何时候都更加重要。浏览互联网时保护自己的一种方法是隐藏您的 IP 地址。 但是为什么要隐藏您的 IP 地址以及如何有效地做到这一点&#xff1f; 隐藏您的 IP 地址有助于保护您的在线匿名性。您的 IP 地址就像您的…

文心智能体 恐怖类游戏

智能体名称&#xff1a;孤岛惊魂 链接&#xff1a;文心智能体平台AgentBuilder | 想象即现实 (baidu.com)https://agents.baidu.com/center/agent/preview/MFhBvA0K9EXXVdjHCcUumadWmWesKvw2 角色与目标设定 &#x1f9d1;&#x1f3fb; 角色&#xff1a;孤岛惊魂是一位虚拟…

龙芯+FreeRTOS+LVGL实战笔记(新)——08RGB闪烁灯

本专栏是笔者另一个专栏《龙芯+RT-Thread+LVGL实战笔记》的姊妹篇,主要的区别在于实时操作系统的不同,章节的安排和任务的推进保持一致,并对源码做了完善与优化,各位可以先到本人主页下去浏览另一专栏的博客列表(目前已撰写36篇,图1所示),再决定是否订阅。此外,也可以…

前端-CDN的理解及CDN一些使用平台

目录 1.CDN的概念 &#xff08;1&#xff09; 分发服务系统 &#xff08;2&#xff09;均衡负荷系统 &#xff08;3&#xff09;运营管理系统 &#xff08;4&#xff09;缓存系统 &#xff08;5&#xff09;支撑系统 2.CDN的基本工作原理 3.CDN使用缓存资源过程 4.CDN…

【已解决】【Windows】【Linux】大数据开发环境配置

常见的虚拟机软件主要有两款 VMware 和 VirtualBox 。VMware是商付费软件&#xff0c;而VirtualBox是免费软件&#xff0c;对于一般用用的话VirtualBox基本可以应付大多数情况了。 步骤&#xff1a; 安装VirtualBox下载镜像在VirtualBox中导入镜像进行适当参数调整 本机电脑…

TCP客户端编码和解码处理:发送和接收指定编码消息

文章目录 引言基于Netty实现TCP客户端Netty发送GBK编码指令Netty接收GBK编码基于Channel发送指令基于ChannelHandlerContext发送指令:建立连接时发送登陆指令开启日志,查看报文信息基于ChannelInboundHandlerAdapter进行业务逻辑处理原生API实现TCP客户端基于DataOutputStrea…

普罗米修斯监控

目录 概念 部署方法 1. 二进制&#xff08;源码包&#xff09; 2. 部署在k8s集群当中&#xff0c;用pod形式部署 概念 prometheus是开源的系统监控和告警。在k8s分布式的容器化管理系统当中&#xff0c;一般都是搭配prometheus来进行监控。它是服务监控系统&#xff0c;也…