Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
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=
|
|
|
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)
|