Commit 9502ba91babbaa0bb3b4845e8ca473f17db4a377

Authored by Wesnydy Ribeiro
1 parent 252c7e28

Remove tranlation step from video generation

core/renderer.py
@@ -59,7 +59,7 @@ def start_video_creator(id): @@ -59,7 +59,7 @@ def start_video_creator(id):
59 """ 59 """
60 global display, ffmpeg 60 global display, ffmpeg
61 # logger.info("Starting video creator server") 61 # logger.info("Starting video creator server")
62 - display = Display(visible=1, size=(800,600)) 62 + display = Display(visible=0, size=(800,600))
63 display.start() 63 display.start()
64 subprocess.call( 64 subprocess.call(
65 [ 65 [
@@ -202,7 +202,7 @@ def keep_alive(conn_send, conn_receive): @@ -202,7 +202,7 @@ def keep_alive(conn_send, conn_receive):
202 print("Renderer listening...") 202 print("Renderer listening...")
203 while True: 203 while True:
204 try: 204 try:
205 - manager.receive_from_queue("translations", run) 205 + manager.receive_from_queue("glosses", run)
206 except KeyboardInterrupt: 206 except KeyboardInterrupt:
207 manager.close_connections() 207 manager.close_connections()
208 os._exit(0) 208 os._exit(0)
core/translator.py
@@ -12,7 +12,6 @@ Author: Wesnydy Lima Ribeiro @@ -12,7 +12,6 @@ Author: Wesnydy Lima Ribeiro
12 E-Mail: wesnydy@lavid.ufpb.br 12 E-Mail: wesnydy@lavid.ufpb.br
13 """ 13 """
14 14
15 -import json  
16 import os 15 import os
17 import pika 16 import pika
18 import PikaManager 17 import PikaManager
@@ -38,18 +37,9 @@ def run(ch, method, properties, body): @@ -38,18 +37,9 @@ def run(ch, method, properties, body):
38 body : string 37 body : string
39 Json string containing the necessary arguments for workers. 38 Json string containing the necessary arguments for workers.
40 """ 39 """
41 - body = json.loads(body)  
42 print ("Translating...") 40 print ("Translating...")
43 - try:  
44 - gloss = traduzir(body["text"].encode("utf8"))  
45 - if body["type"] == "gloss":  
46 - manager.send_to_queue("glosses", gloss, properties)  
47 - elif body["type"] == "video":  
48 - manager.send_to_queue("translations", gloss, properties)  
49 - else:  
50 - print("Unexpected type of request")  
51 - except KeyError:  
52 - print ("Can't find text") 41 + gloss = traduzir(body)
  42 + manager.send_to_queue("translations", gloss, properties)
53 print ("Ok") 43 print ("Ok")
54 44
55 def keep_alive(conn_send, conn_receive): 45 def keep_alive(conn_send, conn_receive):
translate-api/bin/www
@@ -9,7 +9,7 @@ var http = require('http') @@ -9,7 +9,7 @@ var http = require('http')
9 /** 9 /**
10 * Define the port and store in Express. 10 * Define the port and store in Express.
11 */ 11 */
12 -const PORT = 80 12 +const PORT = 80;
13 app.set('port', PORT); 13 app.set('port', PORT);
14 14
15 /** 15 /**
translate-api/controllers/translate.js
@@ -12,33 +12,25 @@ var shortid = require('shortid') @@ -12,33 +12,25 @@ var shortid = require('shortid')
12 , amqp = require('../helpers/amqpManager'); 12 , amqp = require('../helpers/amqpManager');
13 13
14 exports.translate = function(req, res) { 14 exports.translate = function(req, res) {
15 -  
16 - var body = {};  
17 - var id = shortid.generate();  
18 -  
19 if (!req.body.text) 15 if (!req.body.text)
20 return console.log('Text key is missing'); 16 return console.log('Text key is missing');
21 17
22 - body.text = req.body.text;  
23 - body.type = 'gloss'; 18 + var id = shortid.generate();
  19 + var text = req.body.text;
24 20
25 - amqp.sendToQueue(body, id,'texts', false, res);  
26 - amqp.sendToQueue(body, id,'logs', true, res);  
27 - amqp.receiveFromQueue(id, 'glosses', false, res); 21 + amqp.sendToQueue(text, id,'texts', false, res);
  22 + amqp.sendToQueue(text, id,'logs', true, res);
  23 + amqp.receiveFromQueue(id, 'translations', false, res);
28 }; 24 };
29 25
30 exports.urltranslate = function(req, res) { 26 exports.urltranslate = function(req, res) {
31 -  
32 - var body = {};  
33 - var id = shortid.generate();  
34 -  
35 if (!req.body.text) 27 if (!req.body.text)
36 return console.log('Text key missing'); 28 return console.log('Text key missing');
37 29
38 - body.text = req.param('text').toString('utf8');  
39 - body.type = 'gloss'; 30 + var id = shortid.generate();
  31 + var text = req.param('text').toString('utf8');
40 32
41 - amqp.sendToQueue(body, id, 'texts', false, res);  
42 - amqp.sendToQueue(body, id, 'logs', true, res);  
43 - amqp.receiveFromQueue(id, 'glosses', false, res); 33 + amqp.sendToQueue(text, id, 'texts', false, res);
  34 + amqp.sendToQueue(text, id, 'logs', true, res);
  35 + amqp.receiveFromQueue(id, 'translations', false, res);
44 }; 36 };
translate-api/controllers/video.js
@@ -12,17 +12,13 @@ var shortid = require('shortid') @@ -12,17 +12,13 @@ var shortid = require('shortid')
12 , amqp = require('../helpers/amqpManager'); 12 , amqp = require('../helpers/amqpManager');
13 13
14 exports.createVideo = function(req, res) { 14 exports.createVideo = function(req, res) {
  15 + if (!req.body.gloss)
  16 + return console.log('Gloss key missing');
15 17
16 - var body = {};  
17 var id = shortid.generate(); 18 var id = shortid.generate();
  19 + var gloss = req.body.gloss;
18 20
19 - if (!req.body.text)  
20 - return console.log('Text key missing');  
21 -  
22 - body.text = req.body.text;  
23 - body.type = 'video';  
24 -  
25 - amqp.sendToQueue(body, id, 'texts', false, res);  
26 - amqp.sendToQueue(body, id, 'logs', true, res); 21 + amqp.sendToQueue(gloss, id, 'glosses', false, res);
  22 + amqp.sendToQueue(gloss, id, 'logs', true, res);
27 amqp.receiveFromQueue(id, 'videos', false, res); 23 amqp.receiveFromQueue(id, 'videos', false, res);
28 }; 24 };
translate-api/helpers/amqpManager.js
@@ -26,7 +26,7 @@ exports.sendToQueue = function(body, id, queue, durability, res) { @@ -26,7 +26,7 @@ exports.sendToQueue = function(body, id, queue, durability, res) {
26 throw err; 26 throw err;
27 } 27 }
28 ch.assertQueue(queue, {durable : durability}); 28 ch.assertQueue(queue, {durable : durability});
29 - ch.sendToQueue(queue, new Buffer(JSON.stringify(body)), {correlationId : id}); 29 + ch.sendToQueue(queue, new Buffer(body), {correlationId : id});
30 try { 30 try {
31 ch.close(); 31 ch.close();
32 } 32 }