AIIUII(aiiuii创造营2021实时数据_创造营2020reaction)

发布时间:2025-12-10 19:37:47 浏览次数:2

aiiuii创造营2021实时数据_创造营2020reaction-

aiiuii创造营2021实时数据_创造营2020reaction文章浏览阅读188次。该“宇宙分歧终端机”的基本功能通过结合PaddleGan唇型合成、EasyDL自定义图像分类、Wechaty工具、PaddleHub词法分析模型等进行设计与实_将message转换为filebox

Space Disagreement Resolver 为宇宙和谐助力!

在这个宇宙里最大的问题是什么?是分歧!但是怎样可以解决掉分歧呢?

其实人类早已想到了办法,那就是猜拳,但这个看似很公平的方法其实存在两种致命缺陷,就是出手时的快慢和作弊!

就是这两种缺陷而导致其它解决分歧方法的出现,像投票,辩论。但这是本末倒置,应该回到基本!

第一代“分歧终端机”在地球上的出现成功解决了人类猜拳时的快慢和作弊问题!

第二代“宇宙分歧终端机”的量产,将能够解决一切宇宙间的纷争…

效果展示

B站视频链接

https://www.bilibili.com/video/BV1ab4y1k74P?share_source=copy_web

Github链接

https://github.com/yongxinliao-hqu/SpaceDisagreementResolver

欢迎 Star 和 Fork ????

本项目的实现过程

第一步、测试基本模块

对五种手势进行拍照,收集数据(每个手势仅有10张左右图片),通过EasyDL进行训练,并测试EasyDL自定义数据集手势识别

https://aistudio.baidu.com/aistudio/projectdetail/2181186

测试lac词法分析,用于在纠纷细节描述中抽取纠纷对象(尚不够完善)

https://aistudio.baidu.com/aistudio/projectdetail/2183462

测试PaddleGan唇型合成,用于生成规则解释视频

https://aistudio.baidu.com/aistudio/projectdetail/2179537

第二步、将基本功能进行组合,实现“宇宙分歧终端机”效果

References 参考项目

【飞桨创意之星】宋代诗人念诗的秘密–PaddleGAN实现精准唇形合成

https://aistudio.baidu.com/aistudio/projectdetail/2179878

PaddleHub预训练模型LAC完成词法分析

https://aistudio.baidu.com/aistudio/projectdetail/215711

EasyDL零门槛AI开发平台文档

https://ai.baidu.com/ai-doc/EASYDL/pk38n3odv

美图修修裁剪对方出拳

https://pc.meitu.com

paddlehub官网地址:

https://www.paddlepaddle.org.cn/hub

Wechaty 文档

https://wechaty.js.org/docs/

Get a Free Wechaty Token

https://wechaty.js.org/docs/puppet-services/

S05E17 石头剪刀布蜥蜴史波克的玩法

https://www.bilibili.com/video/av15068925

以下内容是对程序的解释,具体执行需要新建一个脚本项目再运行

因为asyncio.run() cannot be called from a running event loop

运行本项目后,下载下列文件并放入你新建的脚本项目

run.pyrun.shimage_get文件夹及其中文件video文件夹及其中文件

0 导入必要的库 设置 全局变量

import osimport cv2import asyncioimport numpy as npimport paddlehub as hubimport randomfrom PIL import Imageimport matplotlibmatplotlib.use('Agg')import matplotlib.pyplot as plt # plt 用于显示图片import matplotlib.image as mpimg # mpimg 用于读取图片from wechaty import (    Contact,    FileBox,    Message,    Wechaty,    ScanStatus,)from wechaty_puppet import MessageTyperobot_state = 0 # 机器人状态 0 初始状态,1 等待用户输入纠纷描述, 2 等待用户决定是否学习规则, 3 等看用户多看几遍, 4 等待用户出拳头target_output = 'Unknown' # 纠纷对象的出拳状态target = 'Unknown' #纠纷对象

希望我今天分享的这篇文章可以帮到您。

1 EasyDL自定义数据集手势识别(基于EasyDL图像分类训练)

################### 1 EasyDL自定义数据集手势识别(基于EasyDL图像分类训练) ###################import jsonimport base64import requests# 配置参数# 目标图片的 本地文件路径,支持jpg/png/bmp格式IMAGE_FILEPATH = ""# top_num: 返回的分类数量,不声明的话默认为 6 个PARAMS = { "top_num": 2}# 服务详情 中的 接口地址MODEL_API_URL = "Your EasyDL API URL"#该模型部署的 API_KEY 以及 SECRET_KEYAPI_KEY = 'Your API_KEY'SECRET_KEY = 'Your SECRET_KEY'# client_id 为官网获取的AK, client_secret 为官网获取的SKhost = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + API_KEY + '&client_secret='+SECRET_KEYdef getAccessToken(host_url):access_token = ''response = requests.get(host_url)if response:print(response.json())access_token = response.json()['access_token']print(access_token)return access_tokendef getUserInputJson(IMAGE_FILEPATH):ACCESS_TOKEN = getAccessToken(host)print("1. 读取目标图片 '{}'".format(IMAGE_FILEPATH))with open(IMAGE_FILEPATH, 'rb') as f:base64_data = base64.b64encode(f.read())base64_str = base64_data.decode('UTF8')print("将 BASE64 编码后图片的字符串填入 PARAMS 的 'image' 字段")PARAMS["image"] = base64_strif not ACCESS_TOKEN:print("2. ACCESS_TOKEN 为空,调用鉴权接口获取TOKEN")auth_url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials"\"&client_id={}&client_secret={}".format(API_KEY, SECRET_KEY)auth_resp = requests.get(auth_url)auth_resp_json = auth_resp.json()ACCESS_TOKEN = auth_resp_json["access_token"]print("新 ACCESS_TOKEN: {}".format(ACCESS_TOKEN))else:print("2. 使用已有 ACCESS_TOKEN")print("3. 向模型接口 'MODEL_API_URL' 发送请求")request_url = "{}?access_token={}".format(MODEL_API_URL, ACCESS_TOKEN)response = requests.post(url=request_url, json=PARAMS)response_json = response.json()response_str = json.dumps(response_json, indent=4, ensure_ascii=False)print("结果:\n{}".format(response_str))return response_json

2 星际分歧终端机游戏规则 (基于《生活大爆炸》谢耳朵的游戏)

################### 2 星际分歧终端机游戏规则 (基于《生活大爆炸》谢耳朵的游戏) ###################def who_win(input1,input2):if input1 == "scissors":if input2 == 'rock':return 2elif input2 == 'spock':return 2elif input2 == 'paper':return 1elif input2 == 'lizard':return 1else:return 0elif input1 == "rock":   if input2 == 'paper':return 2elif input2 == 'spock':return 2elif input2 == 'scissors':return 1elif input2 == 'lizard':return 1else:return 0elif input1 == "paper":  if input2 == 'scissors':return 2elif input2 == 'lizard':return 2elif input2 == 'spock':return 1elif input2 == 'rock':return 1else:return 0elif input1 == "lizard":  if input2 == 'rock':return 2elif input2 == 'scissors':return 2elif input2 == 'paper':return 1elif input2 == 'spock':return 1else:return 0elif input1 == "spock":  if input2 == 'paper':return 2elif input2 == 'lizard':return 2elif input2 == 'rock':return 1elif input2 == 'scissors':return 1else:return 0

3 获取纠纷对象 (基于lac词法分析)

################### 3 获取纠纷对象 (基于lac词法分析)###################lac = hub.Module(name="lac")def getTarget(text):test_text = []test_text.append(text)results = lac.cut(text=test_text, use_gpu=False, batch_size=1, return_tag=True)print(results)for result in results:print(result['word'])print(result['tag'])target = ''for i in range(len(result['word'])):if result['tag'][i]=='ORG' or result['tag'][i]=='nt' :target = result['word'][i] + "的代表"return targetelif result['tag'][i]=='LOC' or result['tag'][i]=='ns' :target = result['word'][i] + "的代表"return targetelif result['tag'][i]=='PER' or result['tag'][i]=='nr' :target = result['word'][i]return targetelif result['tag'][i]=='n':target = result['word'][i]while i + 1 < len(result['word']) and result['tag'][i+1]=='n':target = target + result['word'][i+1]i = i + 1target = target + "的代表"return target

4 组合双方出拳图片并显示结果

################### 4 组合双方出拳图片并显示结果 ###################def image_compose(first_image, second_image, target_input, your_input, who_win):final_image_path = './image/final_image.png'#改变图像大小size = 500,250first_image.thumbnail(size)second_image.thumbnail(size)print (first_image.size, first_image.mode)print (second_image.size, second_image.mode)bia = 40final_image = Image.new('RGB', (2 * 210 + bia*2 , 1* 250 + bia*2), (0, 166, 255)) #创建一个新图# 图片粘贴到对应位置上final_image.paste(first_image, (0+ bia, 0+ bia))final_image.paste(second_image, (233+ bia, 0+ bia))final_image.save(final_image_path) # 保存新图lena = mpimg.imread(final_image_path) plt.imshow(lena)plt.text(198+ bia,150+ bia,'VS',fontsize=15)plt.text(25+ bia,275+ bia,target_input,fontsize=15)plt.text(258+ bia,275+ bia,your_input,fontsize=15)if who_win == 1:plt.text(120+ bia,95+ bia,'You lose!',color='red',fontsize=30)elif who_win == 2:plt.text(120+ bia,95+ bia,'You win!',color='green',fontsize=30)else:plt.text(120+ bia,95+ bia,'Tie!',color='black',fontsize=30)plt.axis('off') # 不显示坐标轴plt.savefig(final_image_path)plt.close('all')

5 定制Wechaty方法

async def on_message(msg: Message):global target_outputglobal robot_stateglobal target#如果收到的message是一句话if isinstance(msg.text(), str) and len(msg.text()) > 0 and msg._payload.type == MessageType.MESSAGE_TYPE_TEXT:print("robot_state = " + str(robot_state))if robot_state == 0:robot_state = 1customer_service_number = random.randint(0,999)await msg.say("欢迎来到星际纠纷调解事务所\n" + str(customer_service_number) +"号调解员正在为您服务\n请您对纠对象及细节进行描述")elif robot_state == 1:robot_state = 2target = getTarget(msg.text())await msg.say("为了解决 您 和 " + target + " 的纠纷,我们建议您使用Space Disagreement Resolver,请问是否需要向您介绍如何使用?(是/否)")elif robot_state == 2 and msg.text() == '是':# 构建一个FileBoxrobot_state = 3file_box_video = FileBox.from_file('/root/paddlejob/workspace/code/video/GameIntroduction.mp4')await msg.say("规则介绍载入中,请稍侯...")await msg.say(file_box_video)await msg.say("该视频将向您介绍Space Disagreement Resolver的使用规则,您可以决定是否使用此方法?(是/否)")elif (robot_state == 3 and msg.text() == '否'):await msg.say("请多看几遍视频:)")elif (robot_state == 2 and msg.text() == '否') or (robot_state == 3 and msg.text() == '是'):robot_state = 4await msg.say("Space Disagreement Resolver将百分百确保双方出拳结果的保密性")await msg.say("正在连线 " + target + "...")await msg.say(target + " 同意通过Space Disagreement Resolver解决与您的纠纷")candidate_output = ['rock','scissors','paper','lizard',"spock"]target_output = candidate_output[random.randint(0,4)]await msg.say(target + " 已将其出拳结果存入Space Disagreement Resolver")await msg.say("请您进行出拳...")else:robot_state = 0#如果收到的message是一张图片且进入了纠纷解决状态if robot_state == 4 and msg.type() == Message.Type.MESSAGE_TYPE_IMAGE:# 将Message转换为FileBoxfile_box_user_image = await msg.to_file_box()# 获取图片名img_name = file_box_user_image.name# 图片保存的路径img_path = './image/' + img_name# 将图片保存为本地文件await file_box_user_image.to_file(file_path=img_path)await msg.say("正在将您的出拳存入Space Disagreement Resolver")# 调用出拳识别函数user_input = getUserInputJson(img_path)prediction = user_input['results'][0]['name']confidence = float(user_input['results'][0]['score'])print(user_input)print(prediction)print(confidence)# 从新的路径获取图片if confidence > 0.3:feedback = predictionelse:feedback = 'Unknown'if feedback == 'Unknown':await msg.say('无法识别您的出拳,请再次出拳')robot_state = 4else:final_result = who_win(target_output,feedback)image_1 = Image.open('/root/paddlejob/workspace/code/image_get/'+target_output+'.png')image_2 = Image.open(img_path)image_compose(image_1, image_2, target_output, feedback, final_result)file_box_final_result = FileBox.from_file('./image/final_image.png')await msg.say(file_box_final_result)if final_result == 1:await msg.say(target + ' ,请按 ' + target+ ' 的意见解决纠纷')await msg.say('感谢您使用Space Disagreement Resolver,再见')robot_state = 0elif final_result == 2:await msg.say('您 胜出了,您 与 ' + target+ ' 之间的纠纷,将按您的意见解决')await msg.say('感谢您使用Space Disagreement Resolver,再见')robot_state = 0else:await msg.say('尚未解决争端,请问是否继续?(是/否)')robot_state = 4async def on_scan(qrcode: str,status: ScanStatus,_data,):print('Status: ' + str(status))print('View QR Code Online: https://wechaty.js.org/qrcode/' + qrcode)async def on_login(user: Contact):print(user)async def main():# 确保我们在环境变量中设置了WECHATY_PUPPET_SERVICE_TOKENif 'WECHATY_PUPPET_SERVICE_TOKEN' not in os.environ:print(''' Error: WECHATY_PUPPET_SERVICE_TOKEN is not found in the environment variables You need a TOKEN to run the Python Wechaty. Please goto our README for details https://github.com/wechaty/python-wechaty-getting-started/#wechaty_puppet_service_token ''')bot = Wechaty()bot.on('scan',      on_scan)bot.on('login',     on_login)bot.on('message',   on_message)await bot.start()print('[Python Wechaty] Ding Dong Bot started.')asyncio.run(main())
需要做网站?需要网络推广?欢迎咨询客户经理 13272073477