完整gpt应用(自用)

news2024/9/25 19:24:08

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, QtWidgets


class 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: ignore
        self.pushButton_2.clicked.connect(Form.close) # type: ignore
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.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__()
        #生成sign
        self.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_hex
        self.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 = ai
        self.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 = voice

    def run(self):
        try:
            if self.ai==0:
                message = requests.post(self.url0).json().get('data').get('content')#dwai 0125
            elif self.ai==1:
                message = requests.post(self.url1).json().get('data').get('content')#dwai 0125
            elif self.ai==2:
                message = requests.get(self.url2).text
            elif self.ai==3:
                message = requests.get(self.url3,json=self.data3).text    #api 4.0
            self.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.comboBox
        comboBox.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=0
        elif ai == 1:
            ai=1
        elif ai == 2:
            ai=2
        elif ai == 3:
            ai=3
        self.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):    #接收name
        self.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.coloradmin.cn/o/2138018.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

9.15 BFS中等 133 Clone Graph review 138 随机链表的复制

133 Clone Graph //错误代码class Solution { public:Node* cloneGraph(Node* node) {//邻接表、BFS---》类似于二叉树的层次遍历if(!node || !node->val) return node;//构造队列queue<Node*> prev;prev.push(node);//构造新的图结点列表vector<Node*> adjList…

ESP8266_MicroPython——ADC_PWM

MicroPython 文章目录 MicroPython前言一、ADC二、PWM 前言 这一节简单学习一下ACD和PWM 一、ADC ADC(analog to digital conversion) 模拟数字转换。意思就是将模拟信号转化成数字信号&#xff0c;由于单片机只能识别二级进制数字&#xff0c;所以外界模拟信号常常会通过 A…

OpenCV结构分析与形状描述符(22)计算图像中某个轮廓或区域的矩函数moments()的使用

操作系统&#xff1a;ubuntu22.04 OpenCV版本&#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言&#xff1a;C11 算法描述 计算一个多边形或光栅化形状直到三阶的所有矩。 该函数计算一个向量形状或光栅化形状直到三阶的矩。结果返回在 cv::Moments 结构中。 函数原型…

数据结构————二叉树基础知识(零基础包会的!)

今天带来数据结构二叉树的知识&#xff0c;保证大家不会离散数学或者没有数据结构基础&#xff0c;也能明明白白的。 一&#xff0c;树 1&#xff0c;树的结构 我们在了解什么是二叉树之前我们先了解下什么是树&#xff0c;树是一种非线性的数据结构&#xff0c;它是由n个节点…

Bootstrap 警告信息(Alerts)使用介绍

本章将讲解警告&#xff08;Alerts&#xff09;以及 Bootstrap 所提供的用于警告的 class。警告&#xff08;Alerts&#xff09;向用户提供了一种定义消息样式的方式。它们为典型的用户操作提供了上下文信息反馈。 您可以为警告框添加一个可选的关闭按钮。为了创建一个内联的可…

C# 实现二维数据数组导出到 Excel

目录 功能需求 范例运行环境 Excel DCOM 配置 设计实现 组件库引入 ​编辑​ 方法设计 生成二维数据数组 核心方法实现 调用示例 总结 功能需求 将数据库查询出来的数据导出并生成 Excel 文件&#xff0c;是项目中经常使用的一项功能。本文将介绍通过数据集生成二维…

基于TCP的网络计算器实现

目录 一. 重新理解协议 二. 序列化与反序列化 2.1 概念 2.2 重新理解 read、write、recv、send 和 tcp 为什么支持全双工 2.3 理解TCP面向字节流 三. 请求应答模块实现 3.1 添加与解析报头 3.2 定制协议&#xff1a; 3.3 Json 四. 计算模块实现…

字典转换(根据字典转换、根据id转换)

一、三种转换方式 翻译场景:序列化时候转换 适用类型: 字典type转中文用户id转用户名部门id转名称附件id转url路径1.1 根据另一个映射字段 翻译保存到此字段 根据创建者createBy的id,查询名称设置到 createName 1.2 直接根据此字段值翻译后替换此字段值 ossId 替换为 url …

医疗监测数据检测系统源码分享

医疗监测数据检测检测系统源码分享 [一条龙教学YOLOV8标注好的数据集一键训练_70全套改进创新点发刊_Web前端展示] 1.研究背景与意义 项目参考AAAI Association for the Advancement of Artificial Intelligence 项目来源AACV Association for the Advancement of Computer…

vue3透传、注入

属性透传 传递给子组件时&#xff0c;没有被子组件消费的属性或事件&#xff0c;常见的如id、class 注意1 1.class、style是合并的&#xff0c;style中如果出现重复的样式&#xff0c;以透传属性为准2.id属性是以透传属性为准&#xff0c;其他情况透传属性名相同&#xff0c…

深度学习云服务器免费使用教程

#云服务器# #深度学习# #人工智能# #计算机视觉# 本文为各位学习深度学习的入门选手而创建&#xff0c;降低深度学习的入门门槛。 谷歌云服务器Colab&#xff1a; T4GPU。限额&#xff0c;需要科学上网&#xff0c;不能使用终端。 谷歌云服务器地址&#xff1a;欢迎使用 C…

C语言 | Leetcode C语言题解之第405题数字转换为十六进制数

题目&#xff1a; 题解&#xff1a; char * toHex(int num){int i0;char *nums(char*)malloc(sizeof(char)*32);unsigned int newnum(unsigned int)num;if(num0){nums[0]0;nums[1]\0;return nums;}while(newnum>1){int flagnewnum%16;newnum/16;if(flag<9){nums[i]flag0…

华为OD机试 - 计算误码率(Python/JS/C/C++ 2024 E卷 100分)

华为OD机试 2024E卷题库疯狂收录中&#xff0c;刷题点这里 专栏导读 本专栏收录于《华为OD机试真题&#xff08;Python/JS/C/C&#xff09;》。 刷的越多&#xff0c;抽中的概率越大&#xff0c;私信哪吒&#xff0c;备注华为OD&#xff0c;加入华为OD刷题交流群&#xff0c;…

Acwing 队列

模拟队列 主要思想&#xff1a;先进先出&#xff08;注意与栈做区分&#xff09;&#xff0c;队尾插入&#xff0c;队头删除。设置一个数组存储数据&#xff0c;队头指针指向队列第一个元素&#xff08;初始为0&#xff09;&#xff0c;队尾指针指向最后一个元素&#xff08;初…

Qt常用控件——QSpinBox

文章目录 QSpinBox核心属性及信号点餐示例 QSpinBox核心属性及信号 QSpinBox或者QDoubleSpinBox表示微调框&#xff0c;带有按钮的输入框&#xff0c;可以用来输入整数/浮点数或者通过点击按钮调整数值大小 QSpinBox和QDoubleSpinBox用法基本相同&#xff0c;本篇以QSpinBox为…

Ubuntu 安装包下载(以20版本 阿里镜像站为例子)

Ubuntu安装包下载 上一篇文章写了一些国内常用的镜像站&#xff0c;这篇以阿里云镜像站Ubuntu20版本为例。 https://mirrors.aliyun.com/ubuntu-releases/ 1.点击自己想要下载的版本 2.点击以amd64.iso为结尾的文件&#xff0c;这个是安装文件&#xff0c;如果是桌面端&…

C++初阶学习——探索STL奥秘——vector的模拟实现

vector的结构比较特殊&#xff0c;成员变量为三个指针 #pragma once #include <iostream> using std::cin; using std::cout; using std::endl;#include <string> using std::string;namespace Yohifo {template<class T>class vector{public:typedef T val…

使用jmeter做性能测试实践过程中需要注意什么

前言 在驾驭Apache JMeter进行性能测试之旅中&#xff0c;深刻理解其特性和限制是至关重要的。以下是提升JMeter效能的关键策略&#xff0c;旨在挖掘其潜力&#xff0c;克服局限&#xff0c;实现精准测试。 1.精确调控线程数 推荐阈值&#xff1a;将线程数控制在300以内&…

模拟视频推到WVP推流列表

效果 1. wvp创建RTMP 2. 使用ffmpeg将本地的视频转为rtmp ffmpeg -re -i F:rtsp\123.mp4 -c copy -f flv rtmp://192.168.1.237:1935/cd/10001?sign=Z4Y3eYeSg

HTML5之canvas绘图

介绍 <canvas> 是 HTML5 引入的一个强大元素&#xff0c;允许直接在网页上进行矢量图形和位图图像的绘制&#xff0c;为网页提供了一个动态图形渲染的平台。这一特性极大丰富了网页的表现力&#xff0c;特别是在数据可视化、游戏开发、交互式图表和动画制作等领域发挥着…