playmak3r commited on
Commit
32b35a3
1 Parent(s): 02e8372

fix: small improvements

Browse files
Files changed (1) hide show
  1. server/app.py +5 -4
server/app.py CHANGED
@@ -1,6 +1,6 @@
1
  from threading import Thread
2
  import redis, time
3
- from flask import Flask, send_from_directory, json, Response, request
4
  from waitress import serve
5
  from flask_cors import CORS, cross_origin
6
  from model import SugoiTranslator
@@ -20,6 +20,7 @@ def queue_process():
20
  else: break
21
 
22
  if len(task_list): task_process(task_list)
 
23
 
24
  def task_process(input_text_list: List[str]):
25
  sugoiTranslator = SugoiTranslator()
@@ -30,10 +31,10 @@ def task_process(input_text_list: List[str]):
30
  def query_translation(input_text: str):
31
  for _ in range(30):
32
  translated_text = redis_client.hget(translated_key, input_text)
33
- if translated_text:
34
  redis_client.hdel(translated_key, input_text)
35
  try: return translated_text.decode('utf-8')
36
- except: return translated_text
37
  time.sleep(1)
38
 
39
 
@@ -61,7 +62,7 @@ def translate_api():
61
  if isinstance(input_text, str) and len(input_text) > 0:
62
  redis_client.lpush(queue_key, input_text) # left push
63
  result = query_translation(input_text)
64
- if result is not None: return json.dumps({ "text": result })
65
  else: return Response(status= 500)
66
  return Response(status= 400)
67
 
 
1
  from threading import Thread
2
  import redis, time
3
+ from flask import Flask, jsonify, send_from_directory, Response, request
4
  from waitress import serve
5
  from flask_cors import CORS, cross_origin
6
  from model import SugoiTranslator
 
20
  else: break
21
 
22
  if len(task_list): task_process(task_list)
23
+
24
 
25
  def task_process(input_text_list: List[str]):
26
  sugoiTranslator = SugoiTranslator()
 
31
  def query_translation(input_text: str):
32
  for _ in range(30):
33
  translated_text = redis_client.hget(translated_key, input_text)
34
+ if translated_text is not None:
35
  redis_client.hdel(translated_key, input_text)
36
  try: return translated_text.decode('utf-8')
37
+ except AttributeError: return translated_text
38
  time.sleep(1)
39
 
40
 
 
62
  if isinstance(input_text, str) and len(input_text) > 0:
63
  redis_client.lpush(queue_key, input_text) # left push
64
  result = query_translation(input_text)
65
+ if result is not None: return jsonify({ "text": result })
66
  else: return Response(status= 500)
67
  return Response(status= 400)
68