スマートWeChatパブリックアカウントのソースコード

[開発要件] Pythonは、次の機能を実現するインテリジェントなパブリックアカウントを開発します
。1。ユーザーが入力したテキストコンテンツに基づいて単純なヒューマンマシンダイアログを実行します
。2。Baidu人工知能インターフェースを呼び出して、ユーザーが入力した画像のテキストを抽出します。
picocrはスクリーンショットテキスト認識用のカスタム作成OCRモジュールであることに注意してください。ソースコードを表示するには、リンクを参照してください。

import werobot
import picocr
import requests
import uuid
robot = werobot.WeRoBot(token='doctorwu')

@robot.subscribe
def hello(message):
	return '欢迎来到无尘的小站,发送带文字的图片,我可以帮你转换成可以复制的文本'

@robot.text
def reply(message):
	content = message.content
	if content[0:3]=='###':
		return 'I will check its pseudomeaning.'
	elif content[-2:]=='吗?':
		msg = content[:-2]+'!'
		msg = msg.replace('你','我')
		return msg
	else:
		return '发送带文字的图片,我可以帮你转换成可以复制的文本'
@robot.image
def image_ocr(message):
	req = requests.get(message.img)
	filename = f'{uuid.uuid4()}.jpg'
	print(filename)
	with open('./screenshots/'+filename,'wb') as f:
		f.write(req.content)
	return picocr.get_ocr_result(filename)

robot.config['HOST'] = '0.0.0.0'
robot.config['PORT'] = 80
robot.run()
元の記事を273件公開 40 件を賞賛 30,000件以上の閲覧

おすすめ

転載: blog.csdn.net/weixin_41855010/article/details/105541063