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)
评论列表
文章目录