joaogante HF staff commited on
Commit
71f0ed8
1 Parent(s): 46e822a

add timeout

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -19,8 +19,8 @@ def run_generation(user_text, top_p, temperature, top_k, max_new_tokens):
19
  model_inputs = tokenizer([user_text], return_tensors="pt").to(torch_device)
20
 
21
  # Start generation on a separate thread, so that we don't block the UI. The text is pulled from the streamer
22
- # in the main thread.
23
- streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
24
  generate_kwargs = dict(
25
  model_inputs,
26
  streamer=streamer,
 
19
  model_inputs = tokenizer([user_text], return_tensors="pt").to(torch_device)
20
 
21
  # Start generation on a separate thread, so that we don't block the UI. The text is pulled from the streamer
22
+ # in the main thread. Adds timeout to the streamer to handle exceptions in the generation thread.
23
+ streamer = TextIteratorStreamer(tokenizer, timeout=10., skip_prompt=True, skip_special_tokens=True)
24
  generate_kwargs = dict(
25
  model_inputs,
26
  streamer=streamer,