-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
31 lines (27 loc) · 1.1 KB
/
server.py
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
import grpc
from concurrent import futures
import image_pb2
import image_pb2_grpc
from PIL import Image
import io
#отображение может не работать как надо на безгуевских осях, но уже 3 часа ночи
class ImageService(image_pb2_grpc.ImageServiceServicer):
def SaveImage(self, request, context):
# сохраняем
image_data = request.image_data
file_path = "image.jpg"
with open(file_path, "wb") as file:
file.write(image_data)
# Открываем сохранённое изображение
image = Image.open(file_path)
image.show()
# ретёрним клиенту
return image_pb2.ImageResponse(status='Image saved and displayed successfully')
def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
image_pb2_grpc.add_ImageServiceServicer_to_server(ImageService(), server)
server.add_insecure_port('[::]:50051')
server.start()
server.wait_for_termination()
if __name__ == '__main__':
serve()