Commit ·
a430811
1
Parent(s): 6dc4bdb
Handle GeneratorExit by yielding UI reset and returning cleanly
Browse files664 unmodified lines6656666676686696703 unmodified lines674675676677678679680664 unmodified lineschat: response_chunk[0],dbg: response_chunk[1],}except Exception as e:print(f"An error occurred during generation: {e}")# If an error happens, add it to the chat history to inform the user.3 unmodified lines]yield {chat: error_history}finally:# 3. ALWAYS reset the UI to an "idle" state upon completion, error, or cancellation.print("Resetting UI state.")yield {txt: gr.update(interactive=True),664 unmodified lines6656666676686696706716726736746756766776786793 unmodified lines683684685686687688689664 unmodified lineschat: response_chunk[0],dbg: response_chunk[1],}except GeneratorExit:# Handle GeneratorExit by resetting UI and returning cleanlyprint("Generation cancelled by user.")yield {txt: gr.update(interactive=True),submit_btn: gr.update(interactive=True),cancel_btn: gr.update(visible=False),}return # Don't re-raise, just return cleanlyexcept Exception as e:print(f"An error occurred during generation: {e}")# If an error happens, add it to the chat history to inform the user.3 unmodified lines]yield {chat: error_history}finally:# Reset UI for normal completion or errorsprint("Resetting UI state.")yield {txt: gr.update(interactive=True),
app.py+10-1