Spaces:
Sleeping
Sleeping
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
app.py
CHANGED
|
@@ -665,15 +665,6 @@ with gr.Blocks(title="LLM Inference with ZeroGPU") as demo:
|
|
| 665 |
chat: response_chunk[0],
|
| 666 |
dbg: response_chunk[1],
|
| 667 |
}
|
| 668 |
-
except GeneratorExit:
|
| 669 |
-
# Handle GeneratorExit by resetting UI and returning cleanly
|
| 670 |
-
print("Generation cancelled by user.")
|
| 671 |
-
yield {
|
| 672 |
-
txt: gr.update(interactive=True),
|
| 673 |
-
submit_btn: gr.update(interactive=True),
|
| 674 |
-
cancel_btn: gr.update(visible=False),
|
| 675 |
-
}
|
| 676 |
-
return # Don't re-raise, just return cleanly
|
| 677 |
except Exception as e:
|
| 678 |
print(f"An error occurred during generation: {e}")
|
| 679 |
# If an error happens, add it to the chat history to inform the user.
|
|
|
|
| 665 |
chat: response_chunk[0],
|
| 666 |
dbg: response_chunk[1],
|
| 667 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
except Exception as e:
|
| 669 |
print(f"An error occurred during generation: {e}")
|
| 670 |
# If an error happens, add it to the chat history to inform the user.
|