Answer the question
In order to leave comments, you need to log in
How can you async and speed up your code?
for i in range(1,string[0]+1):
photo_url = f"Tinder/{i}/1.jpg"
try:
num = compare_faces(photo_url, "s.jpg")
if num == True:
file = open(f"Tinder/{i}/text.txt","r",encoding = "utf-8")
caption = ''
for i in file:
caption = caption + i
file.close()
files = open(photo_url, "rb")
bot.send_photo(message.chat.id,files)
bot.send_message(message.chat.id,caption)
except Exception as e:
print(e)
num = compare_faces(photo_url, "s.jpg")
Answer the question
In order to leave comments, you need to log in
face_encodings
from the image of the standard suggests itself only once, taking it out before the cycle.face_recognition.load_image_file
can be made asynchronous with await on each. bot.send_photo
and bot.send_message
separately.face_recognition.compare_faces
task is computational, so it remains to create several processes according to the number of processor cores, bypassing the queue, and exchange the results (calculated hashes) through the pipe.You can use the multiprocessing module, including using a pool of processes so as not to kill the server))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question