resources.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Harmonbot 作者: Harmon758 项目源码 文件源码
def imagerecognition(self, image_url : str):
        '''Image recognition'''
        try:
            response = clients.clarifai_general_model.predict_by_url(image_url)
        except clarifai.rest.ApiError as e:
            await self.bot.embed_reply(":no_entry: Error: `{}`".format(e.response.json()["outputs"][0]["status"]["details"]))
            return
        if response["status"]["description"] != "Ok":
            await self.bot.embed_reply(":no_entry: Error")
            return
        names = {}
        for concept in response["outputs"][0]["data"]["concepts"]:
            names[concept["name"]] = concept["value"] * 100
        output = ""
        for name, value in sorted(names.items(), key = lambda i: i[1], reverse = True):
            output += "**{}**: {:.2f}%, ".format(name, value)
        output = output[:-2]
        await self.bot.embed_reply(output)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号