-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (33 loc) · 1.17 KB
/
main.py
File metadata and controls
46 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import io
import Augmentor
import numpy as np
import telebot
from PIL import Image
TOKEN = '<insert your token>'
bot = telebot.TeleBot(token=TOKEN)
def fetch_photo(message):
file_id = message.photo[0].file_id
file_info = bot.get_file(file_id)
data = bot.download_file(file_info.file_path)
image_data = io.BytesIO(data)
image = Image.open(image_data)
return image
def distort_photo(image):
images = [[np.asarray(image)]]
pipeline = Augmentor.DataPipeline(images)
pipeline.random_distortion(probability=1, grid_width=4, grid_height=4, magnitude=40)
prepared_images = pipeline.sample(1)
ready_image = Image.fromarray(prepared_images[0][0])
return ready_image
@bot.message_handler(content_types=['photo'])
def send_message(message):
photo = fetch_photo(message)
updated_photo = distort_photo(photo)
output_file = io.BytesIO()
updated_photo.save(output_file, format='jpeg')
output_file.seek(0)
bot.send_photo(message.chat.id, output_file)
@bot.message_handler(func=lambda x: True)
def send_message(message):
bot.send_message(message.chat.id, 'Я умею только в фотки')
bot.polling(none_stop=True)