Browse Source

fix: loglevel de DMP-server

master
glorf 3 months ago committed by Guillaume Dupuy
parent
commit
5ca27227f4
  1. 16
      punctuation-server/server.py

16
punctuation-server/server.py

@ -15,12 +15,13 @@ from deepmultilingualpunctuation import PunctuationModel
class PunctuationServerArgs:
interface: str
port: int
loglevel: int
async def punctuate(websocket):
# Very ugly !
global model
logging.debug(f"Connection from {websocket.remote_address}")
logging.info(f"Connection from {websocket.remote_address}")
async for message in websocket:
try:
data = json.loads(message)
@ -30,23 +31,18 @@ async def punctuate(websocket):
labeled_words = [[x[0], x[1], float(x[2])] for x in model.predict(clean_text)]
await websocket.send(json.dumps({"predictions": labeled_words}))
except json.JSONDecodeError:
logging.warn(f"Could not decode '{message}'")
logging.error(f"Could not decode '{message}'")
async def start():
global model
# Enable loging if needed
#
# logger = logging.getLogger('websockets')
# logger.setLevel(logging.INFO)
# logger.addHandler(logging.StreamHandler())
logging.basicConfig(level=logging.INFO)
args = PunctuationServerArgs(interface=os.environ.get('DMP_SERVER_INTERFACE', '0.0.0.0'),
port=int(os.environ.get('DMP_SERVER_PORT', 2800)))
port=int(os.environ.get('DMP_SERVER_PORT', 2800)),
loglevel=int(os.environ.get('DMP_SERVER_LOGLEVEL', 30)))
logging.basicConfig(level=args.loglevel)
model = PunctuationModel()
async with websockets.serve(punctuate, args.interface, args.port):

Loading…
Cancel
Save