AttributeError: 'coroutine' object has no attribute 'file_path' как исправить?
@dp.message_handler(content_types=['photo'])
async def otvet_na_photo(message: types.Message):
image_id = message.photo[len(message.photo) - 1].file_id
file_path = bot.get_file(image_id).file_path
image_url = "https://api.telegram.org/file/bot{0}/{1}".format(bot, file_path)
if not os.path.exists('temp'):
os.makedirs('temp')
image_name = "{0}.jpg".format(image_id)
print(image_name)
urllib.request.urlretrieve(image_url, "{0}/{1}".format('temp', image_name))
# Replace this with the path to your image
image = Image.open('temp/' + image_name)
# resize the image to a 224x224 with the same strategy as in TM2:
# resizing the image to be at least 224x224 and then cropping from the center
size = (224, 224)
image = ImageOps.fit(image, size, Image.ANTIALIAS)
# turn the image into a numpy array
image_array = np.asarray(image)
# Normalize the image
normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
# Load the image into the array
data[0] = normalized_image_array
# run the inference
prediction = model.predict(data)
max_prediction = list(prediction[0]).index(max(prediction[0]))
list_withpet = ['собака','кошка','хомяк','крыса','паук','курица','овца']
print(max_prediction)
await bot.send_message(message.from_user.id, list_withpet[max_prediction])
Ответы (1 шт):
Автор решения: oleksandrigo
→ Ссылка
Делай так
@dp.message_handler(content_types=['photo'])
async def otvet_na_photo(message: types.Message):
image_id = message.photo[len(message.photo) - 1].file_id
file_path = (await bot.get_file(image_id)).file_path
...