muryshev commited on
Commit
c15aead
·
1 Parent(s): c10b647

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -72,15 +72,19 @@ def generate_tokens(model, generator):
72
  global stop_generation
73
  app.logger.info('generate_tokens started')
74
  #with lock:
75
- for token in generator:
76
- if token == model.token_eos() or stop_generation:
77
- stop_generation = False
78
- app.logger.info('Abort generating')
79
- yield b'' # End of chunk
80
- break
81
-
82
- token_str = model.detokenize([token])#.decode("utf-8", errors="ignore")
83
- yield token_str
 
 
 
 
84
 
85
  @app.route('/stop_generation', methods=['GET'])
86
  def handler_stop_generation():
@@ -233,4 +237,4 @@ def generate_response():
233
  return Response(generate_tokens(model, generator), content_type='text/plain', status=200, direct_passthrough=True)
234
 
235
  if __name__ == "__main__":
236
- app.run(host="0.0.0.0", port=7860, debug=False, threaded=False)
 
72
  global stop_generation
73
  app.logger.info('generate_tokens started')
74
  #with lock:
75
+ try:
76
+ for token in generator:
77
+ if token == model.token_eos() or stop_generation:
78
+ stop_generation = False
79
+ app.logger.info('Abort generating')
80
+ yield b'' # End of chunk
81
+ break
82
+
83
+ token_str = model.detokenize([token])#.decode("utf-8", errors="ignore")
84
+ yield token_str
85
+ except Exception as e:
86
+ app.logger.info('generator exception')
87
+ yield b'' # End of chunk
88
 
89
  @app.route('/stop_generation', methods=['GET'])
90
  def handler_stop_generation():
 
237
  return Response(generate_tokens(model, generator), content_type='text/plain', status=200, direct_passthrough=True)
238
 
239
  if __name__ == "__main__":
240
+ app.run(host="0.0.0.0", port=7860, debug=False, threaded=True)