Commit ·
9466288
1
Parent(s): a430811
Fix cancel generation feature by removing GeneratorExit handler
Browse files- Removed GeneratorExit exception handler from UI layer that was preventing cancellation
- Allow GeneratorExit to propagate to backend generator where cancel_event checks work
- Cancel button now properly stops text generation mid-stream
- UI state resets correctly after cancellation
664 unmodified lines665666667668669670671672673674675676677678679664 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.664 unmodified lines665666667668669670664 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.
app.py-9