{"id":393283,"date":"2024-06-29T10:55:14","date_gmt":"2024-06-29T10:55:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=393283"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=393283","title":{"rendered":"<span>\u041f\u0440\u043e\u0441\u0442\u0430\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0437\u0430\u0434\u0430\u0447 \u0432 Django, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 Kandinsky\u00a02.1<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0418\u0437\u043e\u0431\u0438\u043b\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432 \u0432\u0430\u0448\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0438. \u041c\u043e\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u044b\u043b\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: \u043e\u0434\u0438\u043d GPU, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u0430\u043a\u0443\u044e \u043b\u0438\u0431\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e (\u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 <a href=\"https:\/\/huggingface.co\/ai-forever\/Kandinsky_2.1\" rel=\"noopener noreferrer nofollow\">Kandinsky 2.1<\/a>), \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0441 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 django. Python \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0441 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0432\u043e\u043f\u0440\u043e\u0441\u0430, \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a Celery. \u041a\u0440\u0430\u0442\u043a\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0432\u0448\u0438\u0441\u044c \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439, \u043f\u043e\u0434\u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0448\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, \u0437\u0430 15 \u043c\u0438\u043d\u0443\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0443. \u041d\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u043b\u0438\u044f\u044e\u0449\u0435\u0439 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 Celery, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <em>Kandinsky\u00a02.1, <\/em>\u0432\u0435\u0441\u0430 \u0438\u043c\u0435\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u044a\u0435\u043c. \u041f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0430\u0441\u044c \u0432 <a href=\"https:\/\/stackoverflow.com\/questions\/63645357\/using-pytorch-with-celery\" rel=\"noopener noreferrer nofollow\">stackoverflow<\/a>. \u041f\u043e\u043f\u044b\u0442\u043a\u0438 \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u0443 \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u0443 \u0432 \u00ab\u0441\u0435\u043b\u044c\u0434\u0435\u0440\u0435\u0439\u00bb, \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u0438 \u043a \u043d\u043e\u0432\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u0435\u0434\u0435\u0442 \u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/medium.com\/super\/scaling-allennlp-pytorch-in-production-56746c76d710\" rel=\"noopener noreferrer nofollow\">Scaling AllenNLP\/PyTorch in Production<\/a>, \u0432\u043c\u0435\u0441\u0442\u043e Celery \u0430\u0432\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ZeroMQ, \u0441 \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0431\u0443\u0434\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 CPU, \u0432\u043e\u043e\u0431\u0449\u0435\u043c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044e. <a href=\"https:\/\/github.com\/zeromq\" rel=\"noopener noreferrer nofollow\">ZeroMQ<\/a> &#8212; \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c \u043e\u0431\u043c\u0435\u043d\u0430 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0438 django, \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0444\u043e\u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Django Channels, <a href=\"https:\/\/channels.readthedocs.io\/en\/stable\/topics\/worker.html\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u0438 \u0444\u043e\u043d\u043e\u0432\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/a>. <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c:<\/h4>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0438\u0437 web \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 Django.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 Django, \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b Django.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e TCP ZeroMQ \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e TCP ZeroMQ \u0432 \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u043a\u0430\u043d\u0430\u043b Django.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c javascript \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u0412 \u043c\u043e\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442 &#8212; \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WebSocket, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 Django Channels, \u0432\u044b \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<pre><code class=\"javascript\">var ws_wall = new WebSocket(\"ws:\/\/\"+ IP_ADDR +\":\"+PORT+\"\/\");  ws_wall.onmessage = function(event) {   \/\/ \u0447\u0442\u043e \u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c }  \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 Django function send_wall() {     var body = document.getElementById('id_body');     if (body.value == \"\") {         return false;     }     if (ws_wall.readyState != WebSocket.OPEN) {         return false;     }     var data = JSON.stringify({body: body.value,                                event: \"wallpost\"});     ws_wall.send(data); }<\/code><\/pre>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 Django Channels. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e, \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441 Django, \u043d\u0435 \u0443\u0432\u0438\u0434\u044f\u0442 \u0447\u0435\u0433\u043e \u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 orm django \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430, \u043f\u043e \u043a\u043e\u0434\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u0441\u0451 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<pre><code class=\"python\">import json from channels.generic.websocket import AsyncJsonWebsocketConsumer from myapp.models import User, Post from asgiref.sync import sync_to_async from django.utils import dateformat  class WallHandler(AsyncJsonWebsocketConsumer):     async def connect(self):         \"\"\"         \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f         \"\"\"         self.room_group_name = \"wall\"         self.sender_id = self.scope['user'].id         self.sender_name = self.scope['user']         if str(self.scope['user']) != 'AnonymousUser':             self.path_data = self.scope['user'].path_data         await self.channel_layer.group_add(             self.room_group_name,             self.channel_name         )         await self.accept()              async def disconnect(self, close_code):         \"\"\"         \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f         \u043f\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0443         \"\"\"         print(\"error code: \", close_code)         await self.channel_layer.group_discard(             self.room_group_name,             self.channel_name         )                    async def receive(self, text_data):         \"\"\"         \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u043a\u0438\u043b\u0438\u0435\u043d\u0442\u0430 (WebSocket)         \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435         \"\"\"         response = json.loads(text_data)         event = response.get(\"event\", None)         if self.scope['user'].is_authenticated:              if event == \"wallpost\":                 post = Post()                 post.body = response[\"body\"]                 post.path_data = self.path_data                 post.user_post = self.scope['user']                 post_async = sync_to_async(post.save) # \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c Django                 await post_async()                  \"\"\"                 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 Django,                  \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f                  \u0432 \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b Django                 \"\"\"                 _temp_dict = {}                 _temp_dict[\"body\"] = response[\"body\"]                 _temp_dict[\"path_data\"] = self.path_data                 _temp_dict[\"post\"] = str(post.id)                 _temp_dict[\"type\"] = \"triggerWorker\"                 _temp_dict[\"room_group_name\"] = self.room_group_name                 await self.channel_layer.send('nnapp', _temp_dict) # \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 await \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430                 \"\"\"                 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443,                 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443,                  \u0431\u0435\u0437 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438                 \"\"\"                 _data = {\"type\": \"wallpost\",                          \"timestamp\": dateformat.format(post.date_post, 'U'),                          \"text\":response[\"body\"],                          \"user_post\": str(self.sender_name),                          \"user_id\": str(self.sender_id),                          \"id\": str(post.id),                          \"status\" : \"wallpost\"                         }                 await self.channel_layer.group_send(self.room_group_name, _data)     async def wallpost(self, res):         \"\"\"           \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443(WebSocket)         \"\"\"         await self.send(text_data=json.dumps(res))                <\/code><\/pre>\n<p> <strong>\u0412\u0410\u0416\u041d\u041e!!!<\/strong> \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 <em>asgi.py<\/em> Django \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"python\">\"\"\" ASGI config for app project.  It exposes the ASGI callable as a module-level variable named ``application``.  For more information on this file, see https:\/\/docs.djangoproject.com\/en\/3.2\/howto\/deployment\/asgi\/ \"\"\"  import os import django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings') django.setup()  from django.core.asgi import get_asgi_application from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter import app.routing from wall import nnapp  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')  application = ProtocolTypeRouter({     \"http\": get_asgi_application(),     \"websocket\": AuthMiddlewareStack(         URLRouter(             app.routing.websocket_urlpatterns,         )     ),     # \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b Django     \"channel\": ChannelNameRouter({         \"nnapp\": nnapp.NNHandler.as_asgi(),     }), })<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043c \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u043a\u0430\u043d\u0430\u043b Django, \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u043e\u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b <em>nnapp.py,<\/em> \u043a\u043e\u043f\u0438\u0440\u0443\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/medium.com\/super\/scaling-allennlp-pytorch-in-production-56746c76d710\" rel=\"noopener noreferrer nofollow\">Scaling AllenNLP\/PyTorch in Production<\/a> \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u044e \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u043d\u0443\u0436\u0434.<\/p>\n<pre><code class=\"python\">from myapp.models import User, Post from asgiref.sync import async_to_sync from channels.consumer import SyncConsumer from channels.layers import get_channel_layer import uuid import os import json import zlib import pickle import zmq  # \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 work_publisher = None result_subscriber = None TOPIC = 'snaptravel'  RECEIVE_PORT = 5555 SEND_PORT = 5556   # \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a channel layer channel_layer = get_channel_layer()  # \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0431\u0430\u0439\u0442\u0430\u043c\u0438 def compress(obj):     p = pickle.dumps(obj)     return zlib.compress(p)  def decompress(pickled):     p = zlib.decompress(pickled)     return pickle.loads(p)      def start():     global work_publisher, result_subscriber     context = zmq.Context()     work_publisher = context.socket(zmq.PUB)     work_publisher.connect(f'tcp:\/\/127.0.0.1:{SEND_PORT}')   def _parse_recv_for_json(result, topic=TOPIC):     compressed_json = result[len(topic) + 1:]     return decompress(compressed_json)  def send(args, model=None, topic=TOPIC):     id = str(uuid.uuid4())     message = {'body': args[\"title\"], 'model': model, 'id': id}     compressed_message = compress(message)     work_publisher.send(f'{topic} '.encode('utf8') + compressed_message)     return id  def get(id, topic=TOPIC):     context = zmq.Context()     result_subscriber = context.socket(zmq.SUB)     result_subscriber.setsockopt(zmq.SUBSCRIBE, topic.encode('utf8'))     result_subscriber.connect(f'tcp:\/\/127.0.0.1:{RECEIVE_PORT}')     result = _parse_recv_for_json(result_subscriber.recv())     while result['id'] != id:         result = _parse_recv_for_json(result_subscriber.recv())     result_subscriber.close()     if result.get('error'):         raise Exception(result['error_msg'])     return result    # \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 def send_and_get(args, model=None):     id = send(args, model=model)     res = get(id)     namefile = f'{id}.jpg'     res['prediction'][0].save(f'media\/data_image\/{args[\"path_data\"]}\/{namefile}', format=\"JPEG\")     post = Post.objects.get(id=args[\"post\"])      post.image = namefile     post.save()     _data = {\"type\": \"wallpost\", \"status\":\"Kandinsky-2.1\", \"path_data\": args[\"path_data\"],              \"data\": f'{namefile}', \"post\":args[\"post\"]}     # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u0430\u043d\u0430\u043b Django Channels     async_to_sync(channel_layer.group_send)(args[\"room_group_name\"], _data)  # \u0437\u0430\u043f\u0443\u0441\u043a \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 \u0441 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c ZeroMQ class NNHandler(SyncConsumer):     start()     def triggerWorker(self, message):         print (\"data for a background task: \", message)         send_and_get(message, model='Kandinsky-2.1')<\/code><\/pre>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440 ZeroMQ \u0441 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 <a href=\"https:\/\/github.com\/ai-forever\/Kandinsky-2\" rel=\"noopener noreferrer nofollow\">Kadinsky 2.1<\/a>, \u043f\u043e \u0431\u043e\u043b\u044c\u0448\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043a\u043e\u0434\u043e\u043c \u0441\u0442\u0430\u0442\u044c\u0438, \u0441 \u043d\u0435\u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f\u043c\u0438. \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0440\u0443\u0441\u0441\u043a\u0438\u043c \u044f\u0437\u044b\u043a\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430 <a href=\"https:\/\/huggingface.co\/Helsinki-NLP\/opus-mt-ru-en\" rel=\"noopener noreferrer nofollow\">Helsinki-NLP\/opus-mt-ru-en<\/a><em>.<\/em> <\/p>\n<pre><code class=\"python\">import os, time from types import SimpleNamespace import zmq import zlib import pickle import torch.multiprocessing as mp import threading import cv2 from kandinsky2 import get_kandinsky2 from transformers import AutoModelForSeq2SeqLM, AutoTokenizer  import uuid  QUEUE_SIZE = mp.Value('i', 0)  def compress(obj):     p = pickle.dumps(obj)     return zlib.compress(p)  def decompress(pickled):     p = zlib.decompress(pickled)     return pickle.loads(p)  TOPIC = 'snaptravel' prediction_functions = {}  RECEIVE_PORT = 5556 SEND_PORT = 5555  # \u00ab\u043c\u043e\u0434\u0435\u043b\u044c\u00bb \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 model = get_kandinsky2('cuda', task_type='text2img', model_version='2.1', use_flash_attention=False)  # \u00ab\u043c\u043e\u0434\u0435\u043b\u044c\u00bb \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a tokenizer = AutoTokenizer.from_pretrained(\"Helsinki-NLP\/opus-mt-ru-en\") model_translater = AutoModelForSeq2SeqLM.from_pretrained(\"Helsinki-NLP\/opus-mt-ru-en\")   def _parse_recv_for_json(result, topic=TOPIC):     compressed_json = result[len(topic) + 1:]     return decompress(compressed_json)  def _decrease_queue():     with QUEUE_SIZE.get_lock():         QUEUE_SIZE.value -= 1  def _increase_queue():     with QUEUE_SIZE.get_lock():         QUEUE_SIZE.value += 1      def send_prediction(message, result_publisher, topic=TOPIC):     _increase_queue()     model_name = message['model']     body = message['body']     id = message['id']          # \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u00ab\u043c\u043e\u0434\u0435\u043b\u0438\u00bb \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a     tokenized_text = tokenizer([str(body).lower()], return_tensors='pt')      # \u043f\u0435\u0440\u0435\u0432\u043e\u0434     translation = model_translater.generate(**tokenized_text)     body = tokenizer.batch_decode(translation, skip_special_tokens=True)[0]     print(body)      # \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f     images = model.generate_text2img(         str(body).lower(),          num_steps=70,         batch_size=1,          guidance_scale=4,         h=768, w=768,         sampler='p_sampler',          prior_cf_scale=4,         prior_steps=\"5\"     )     result = {\"result\": images}      if result.get('result') is None:         time.sleep(1)         compressed_message = compress({'error': True, 'error_msg': 'No result was given: ' + str(result), 'id': id})         result_publisher.send(f'{topic} '.encode('utf8') + compressed_message)         _decrease_queue()         return            prediction = result['result']     compressed_message = compress({'prediction': prediction, 'id': id})     result_publisher.send(f'{topic} '.encode('utf8') + compressed_message)     _decrease_queue()     print (\"SERVER\", message, f'{topic} '.encode('utf8'))  def queue_size():     return QUEUE_SIZE.value  def load_models():     models = SimpleNamespace()     return models  def start():     global prediction_functions      models = load_models()     prediction_functions = {     'queue': queue_size     }      print(f'Connecting to {RECEIVE_PORT} in server', TOPIC.encode('utf8'))     context = zmq.Context()     work_subscriber = context.socket(zmq.SUB)     work_subscriber.setsockopt(zmq.SUBSCRIBE, TOPIC.encode('utf8'))     work_subscriber.bind(f'tcp:\/\/127.0.0.1:{RECEIVE_PORT}')      # send work     print(f'Connecting to {SEND_PORT} in server')     result_publisher = context.socket(zmq.PUB)     result_publisher.bind(f'tcp:\/\/127.0.0.1:{SEND_PORT}')      print('Server started')     while True:         message = _parse_recv_for_json(work_subscriber.recv())         threading.Thread(target=send_prediction, args=(message, result_publisher), kwargs={'topic': TOPIC}).start()  if __name__ == '__main__':   start()<\/code><\/pre>\n<blockquote>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c django channels \u0434\u043b\u044f \u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c:<br \/><code>python manage.py runworker nnapp<\/code><\/p>\n<\/blockquote>\n<p>\u042d\u0442\u0438 \u0447\u0430\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u0438\u0437 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u043c\u043e\u0435\u0439 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0438, \u043d\u0430 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u0438 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0439 \u0447\u0442\u043e \u0434\u0430\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043d\u0438\u0438. \u0425\u043e\u0440\u043e\u0448\u0438\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 <a href=\"https:\/\/n0lean.github.io\/2018\/08\/06\/Build-a-Pytorch-Server-with-Tornado-and-Docker\/\" rel=\"noopener noreferrer nofollow\">Build a Pytorch Server with celery and RabbitMQ<\/a>, \u043d\u043e \u043f\u043b\u043e\u0445\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u0439 \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u043b\u043e\u0436\u043d\u0435\u0439 \u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0447\u0435\u043c \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u0435\u043c\u044b\u0439 \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435. \u0411\u044b\u043b\u0438 \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0438\u0434\u0435\u0439, \u043d\u043e \u0440\u0435\u0448\u0438\u043b \u043f\u043e\u0439\u0442\u0438 \u043f\u043e \u043f\u0443\u0442\u0438 \u043d\u0430\u0438\u043c\u0435\u043d\u044c\u0448\u0435\u0433\u043e \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u0435\u043d\u0438\u044f&#8230; \u0414\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u043c gpu, \u043d\u0443\u0436\u0435\u043d \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e gpu, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0447\u0443\u0436\u043e\u0433\u043e \u0442\u0440\u0443\u0434\u0430. \u0420\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 <a href=\"https:\/\/github.com\/naturalkind\/social-network\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/naturalkind\/social-network<\/a>. <\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/730238\/\"> https:\/\/habr.com\/ru\/articles\/730238\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u044c\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u044b\u0447\u0438\u0441\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432. \u0418\u0437\u043e\u0431\u0438\u043b\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432 \u0432\u0430\u0448\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0435\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0438. \u041c\u043e\u044f \u0437\u0430\u0434\u0430\u0447\u0430 \u0431\u044b\u043b\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0440\u0435\u0433\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: \u043e\u0434\u0438\u043d GPU, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u0430\u043a\u0443\u044e \u043b\u0438\u0431\u043e \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e (\u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u0431\u0443\u0434\u0435\u0442 <a href=\"https:\/\/huggingface.co\/ai-forever\/Kandinsky_2.1\" rel=\"noopener noreferrer nofollow\">Kandinsky 2.1<\/a>), \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0441 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u044b\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0432 django. Python \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0441 \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u043e\u0439 \u0432\u043e\u043f\u0440\u043e\u0441\u0430, \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a Celery. \u041a\u0440\u0430\u0442\u043a\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0432\u0448\u0438\u0441\u044c \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439, \u043f\u043e\u0434\u0441\u043e\u0437\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0448\u044c \u0437\u0430\u0434\u0430\u0447\u0443, \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e, \u0437\u0430 15 \u043c\u0438\u043d\u0443\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0443. \u041d\u043e \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0432\u043b\u0438\u044f\u044e\u0449\u0435\u0439 \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430. \u041a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 Celery, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 <em>Kandinsky\u00a02.1, <\/em>\u0432\u0435\u0441\u0430 \u0438\u043c\u0435\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043e\u0431\u044a\u0435\u043c. \u041f\u043e\u0434\u043e\u0431\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0430\u0441\u044c \u0432 <a href=\"https:\/\/stackoverflow.com\/questions\/63645357\/using-pytorch-with-celery\" rel=\"noopener noreferrer nofollow\">stackoverflow<\/a>. \u041f\u043e\u043f\u044b\u0442\u043a\u0438 \u043e\u0431\u043e\u0439\u0442\u0438 \u044d\u0442\u0443 \u043f\u0440\u0435\u0433\u0440\u0430\u0434\u0443 \u0432 \u00ab\u0441\u0435\u043b\u044c\u0434\u0435\u0440\u0435\u0439\u00bb, \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043b\u0438 \u043a \u043d\u043e\u0432\u044b\u043c \u043e\u0448\u0438\u0431\u043a\u0430\u043c. \u041e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u0435\u0434\u0435\u0442 \u043a \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 <a href=\"https:\/\/medium.com\/super\/scaling-allennlp-pytorch-in-production-56746c76d710\" rel=\"noopener noreferrer nofollow\">Scaling AllenNLP\/PyTorch in Production<\/a>, \u0432\u043c\u0435\u0441\u0442\u043e Celery \u0430\u0432\u0442\u043e\u0440 \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c ZeroMQ, \u0441 \u044d\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u0431\u0443\u0434\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438. \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442\u0441\u044f \u0432 CPU, \u0432\u043e\u043e\u0431\u0449\u0435\u043c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0447\u0442\u0435\u043d\u0438\u044e. <a href=\"https:\/\/github.com\/zeromq\" rel=\"noopener noreferrer nofollow\">ZeroMQ<\/a> &#8212; \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c \u043e\u0431\u043c\u0435\u043d\u0430 \u043c\u0435\u0436\u0434\u0443 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0438 django, \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0444\u043e\u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Django Channels, <a href=\"https:\/\/channels.readthedocs.io\/en\/stable\/topics\/worker.html\" rel=\"noopener noreferrer nofollow\">\u0440\u0430\u0431\u043e\u0447\u0438\u0435 \u0438 \u0444\u043e\u043d\u043e\u0432\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/a>. <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u043d\u044b\u0439 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c:<\/h4>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c, \u0438\u0437 web \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 Django.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 Django, \u043f\u0435\u0440\u0435\u0441\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b Django.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e TCP ZeroMQ \u043a \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e TCP ZeroMQ \u0432 \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u043a\u0430\u043d\u0430\u043b Django.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e.<\/p>\n<\/li>\n<\/ol>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0430\u044f \u0447\u0430\u0441\u0442\u044c javascript \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445. \u0412 \u043c\u043e\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442 &#8212; \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WebSocket, \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 Django Channels, \u0432\u044b \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u0432 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u0435 \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0434\u043b\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0444\u043e\u043d\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<pre><code class=\"javascript\">var ws_wall = new WebSocket(\"ws:\/\/\"+ IP_ADDR +\":\"+PORT+\"\/\");  ws_wall.onmessage = function(event) {   \/\/ \u0447\u0442\u043e \u0442\u043e \u0434\u0435\u043b\u0430\u0435\u043c \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u043e\u0442\u0432\u0435\u0442\u043e\u043c }  \/\/ \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 Django function send_wall() {     var body = document.getElementById('id_body');     if (body.value == \"\") {         return false;     }     if (ws_wall.readyState != WebSocket.OPEN) {         return false;     }     var data = JSON.stringify({body: body.value,                                event: \"wallpost\"});     ws_wall.send(data); }<\/code><\/pre>\n<p>\u0421\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 Django Channels. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e, \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0441 Django, \u043d\u0435 \u0443\u0432\u0438\u0434\u044f\u0442 \u0447\u0435\u0433\u043e \u0442\u043e \u043d\u043e\u0432\u043e\u0433\u043e, \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043a\u043e\u0434\u0430 \u0438\u0437 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 orm django \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b\u0430, \u043f\u043e \u043a\u043e\u0434\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0447\u0442\u043e \u0432\u0441\u0451 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<pre><code class=\"python\">import json from channels.generic.websocket import AsyncJsonWebsocketConsumer from myapp.models import User, Post from asgiref.sync import sync_to_async from django.utils import dateformat  class WallHandler(AsyncJsonWebsocketConsumer):     async def connect(self):         \"\"\"         \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f         \"\"\"         self.room_group_name = \"wall\"         self.sender_id = self.scope['user'].id         self.sender_name = self.scope['user']         if str(self.scope['user']) != 'AnonymousUser':             self.path_data = self.scope['user'].path_data         await self.channel_layer.group_add(             self.room_group_name,             self.channel_name         )         await self.accept()              async def disconnect(self, close_code):         \"\"\"         \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0442\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f         \u043f\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u0433\u0440\u0443\u043f\u043f\u0443         \"\"\"         print(\"error code: \", close_code)         await self.channel_layer.group_discard(             self.room_group_name,             self.channel_name         )                    async def receive(self, text_data):         \"\"\"         \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 \u043a\u0438\u043b\u0438\u0435\u043d\u0442\u0430 (WebSocket)         \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u044c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435         \"\"\"         response = json.loads(text_data)         event = response.get(\"event\", None)         if self.scope['user'].is_authenticated:              if event == \"wallpost\":                 post = Post()                 post.body = response[\"body\"]                 post.path_data = self.path_data                 post.user_post = self.scope['user']                 post_async = sync_to_async(post.save) # \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0441 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c Django                 await post_async()                  \"\"\"                 \u0438\u0437 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043a\u0430\u043d\u0430\u043b\u0430 Django,                  \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f                  \u0432 \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b Django                 \"\"\"                 _temp_dict = {}                 _temp_dict[\"body\"] = response[\"body\"]                 _temp_dict[\"path_data\"] = self.path_data                 _temp_dict[\"post\"] = str(post.id)                 _temp_dict[\"type\"] = \"triggerWorker\"                 _temp_dict[\"room_group_name\"] = self.room_group_name                 await self.channel_layer.send('nnapp', _temp_dict) # \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 await \u043d\u0435 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430                 \"\"\"                 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443,                 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u0433\u043e\u0442\u043e\u0432\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443,                  \u0431\u0435\u0437 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0451\u043c\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438                 \"\"\"                 _data = {\"type\": \"wallpost\",                          \"timestamp\": dateformat.format(post.date_post, 'U'),                          \"text\":response[\"body\"],                          \"user_post\": str(self.sender_name),                          \"user_id\": str(self.sender_id),                          \"id\": str(post.id),                          \"status\" : \"wallpost\"                         }                 await self.channel_layer.group_send(self.room_group_name, _data)     async def wallpost(self, res):         \"\"\"           \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443(WebSocket)         \"\"\"         await self.send(text_data=json.dumps(res))                <\/code><\/pre>\n<p> <strong>\u0412\u0410\u0416\u041d\u041e!!!<\/strong> \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 <em>asgi.py<\/em> Django \u043f\u0440\u043e\u0435\u043a\u0442\u0430.<\/p>\n<pre><code class=\"python\">\"\"\" ASGI config for app project.  It exposes the ASGI callable as a module-level variable named ``application``.  For more information on this file, see https:\/\/docs.djangoproject.com\/en\/3.2\/howto\/deployment\/asgi\/ \"\"\"  import os import django os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings') django.setup()  from django.core.asgi import get_asgi_application from channels.auth import AuthMiddlewareStack from channels.routing import ProtocolTypeRouter, URLRouter, ChannelNameRouter import app.routing from wall import nnapp  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')  application = ProtocolTypeRouter({     \"http\": get_asgi_application(),     \"websocket\": AuthMiddlewareStack(         URLRouter(             app.routing.websocket_urlpatterns,         )     ),     # \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u0430\u043d\u0430\u043b Django     \"channel\": ChannelNameRouter({         \"nnapp\": nnapp.NNHandler.as_asgi(),     }), })<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u043c \u00ab\u0434\u0440\u0443\u0433\u043e\u0439\u00bb \u043a\u0430\u043d\u0430\u043b Django, \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0444\u043e\u043d\u043e\u0432\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. \u0412 \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b <em>nnapp.py,<\/em> \u043a\u043e\u043f\u0438\u0440\u0443\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/medium.com\/super\/scaling-allennlp-pytorch-in-production-56746c76d710\" rel=\"noopener noreferrer nofollow\">Scaling AllenNLP\/PyTorch in Production<\/a> \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u044e \u0434\u043b\u044f \u0441\u0432\u043e\u0438\u0445 \u043d\u0443\u0436\u0434.<\/p>\n<pre><code class=\"python\">from myapp.models import User, Post from asgiref.sync import async_to_sync from channels.consumer import SyncConsumer from channels.layers import get_channel_layer import uuid import os import json import zlib import pickle import zmq  # \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 work_publisher = None result_subscriber = None TOPIC = 'snaptravel'  RECEIVE_PORT = 5555 SEND_PORT = 5556   # \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a channel layer channel_layer = get_channel_layer()  # \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0431\u0430\u0439\u0442\u0430\u043c\u0438 def compress(obj):     p = pickle.dumps(obj)     return zlib.compress(p)  def decompress(pickled):     p = zlib.decompress(pickled)     return pickle.loads(p)      def start():     global work_publisher, result_subscriber     context = zmq.Context()     work_publisher = context.socket(zmq.PUB)     work_publisher.connect(f'tcp:\/\/127.0.0.1:{SEND_PORT}')   def _parse_recv_for_json(result, topic=TOPIC):     compressed_json = result[len(topic) + 1:]     return decompress(compressed_json)  def send(args, model=None, topic=TOPIC):     id = str(uuid.uuid4())     message = {'body': args[\"title\"], 'model': model, 'id': id}     compressed_message = compress(message)     work_publisher.send(f'{topic} '.encode('utf8') + compressed_message)     return id  def get(id, topic=TOPIC):     context = zmq.Context()     result_subscriber = context.socket(zmq.SUB)     result_subscriber.setsockopt(zmq.SUBSCRIBE, topic.encode('utf8'))     result_subscriber.connect(f'tcp:\/\/127.0.0.1:{RECEIVE_PORT}')     result = _parse_recv_for_json(result_subscriber.recv())     while result['id'] != id:         result = _parse_recv_for_json(result_subscriber.recv())     result_subscriber.close()     if result.get('error'):         raise Exception(result['error_msg'])     return result    # \u044d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u044c\u0441\u044f \u043e\u0442 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u0430 \u0438\u0437 \u0441\u0442\u0430\u0442\u044c\u0438 def send_and_get(args, model=None):     id = send(args, model=model)     res = get(id)     namefile = f'{id}.jpg'     res['prediction'][0].save(f'media\/data_image\/{args[\"path_data\"]}\/{namefile}', format=\"JPEG\")     post = Post.objects.get(id=args[\"post\"])      post.image = namefile     post.save()     _data = {\"type\": \"wallpost\", \"status\":\"Kandinsky-2.1\", \"path_data\": args[\"path_data\"],              \"data\": f'{namefile}', \"post\":args[\"post\"]}     # \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u0430\u043d\u0430\u043b Django Channels     async_to_sync(channel_layer.group_send)(args[\"room_group_name\"], _data)  # \u0437\u0430\u043f\u0443\u0441\u043a \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043e\u0433\u043e <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-393283","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/393283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=393283"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/393283\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=393283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=393283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=393283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}