fix: Resolve array comparison error and add inference stop functionality

- Fix ambiguous truth value error in InferencePipeline result handling
- Add stop inference button to deployment dialog with proper UI state management
- Improve error handling for tuple vs dict result types

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Masonmason 2025-07-17 09:46:31 +08:00
parent c94eb5ee30
commit 183300472e
2 changed files with 54 additions and 5 deletions

View File

@ -215,8 +215,14 @@ class PipelineStage:
timeout_start = time.time() timeout_start = time.time()
while time.time() - timeout_start < 5.0: # 5 second timeout while time.time() - timeout_start < 5.0: # 5 second timeout
result = self.multidongle.get_latest_inference_result(timeout=0.1) result = self.multidongle.get_latest_inference_result(timeout=0.1)
# Check if result is not None and not an empty dict # Check if result is not None and not an empty dict/tuple
if result is not None and (not isinstance(result, dict) or result): if result is not None:
if isinstance(result, dict):
if result: # Non-empty dict
inference_result = result
break
else:
# For tuple results like (probability, result_string)
inference_result = result inference_result = result
break break
time.sleep(0.01) time.sleep(0.01)

View File

@ -220,6 +220,12 @@ class DeploymentDialog(QDialog):
self.deploy_button.setEnabled(False) self.deploy_button.setEnabled(False)
button_layout.addWidget(self.deploy_button) button_layout.addWidget(self.deploy_button)
self.stop_button = QPushButton("Stop Inference")
self.stop_button.clicked.connect(self.stop_deployment)
self.stop_button.setEnabled(False)
self.stop_button.setVisible(False)
button_layout.addWidget(self.stop_button)
button_layout.addStretch() button_layout.addStretch()
self.close_button = QPushButton("Close") self.close_button = QPushButton("Close")
@ -518,6 +524,29 @@ Stage Configurations:
self.deployment_worker.start() self.deployment_worker.start()
def stop_deployment(self):
"""Stop the current deployment/inference."""
if self.deployment_worker and self.deployment_worker.isRunning():
reply = QMessageBox.question(self, "Stop Inference",
"Are you sure you want to stop the inference?",
QMessageBox.Yes | QMessageBox.No)
if reply == QMessageBox.Yes:
self.deployment_log.append("Stopping inference...")
self.status_label.setText("Stopping inference...")
self.deployment_worker.stop()
self.deployment_worker.wait(3000) # Wait up to 3 seconds
# Update UI
self.stop_button.setEnabled(False)
self.stop_button.setVisible(False)
self.deploy_button.setEnabled(True)
self.close_button.setText("Close")
self.progress_bar.setVisible(False)
self.deployment_log.append("Inference stopped.")
self.status_label.setText("Inference stopped")
self.dongle_status.setText("Pipeline stopped")
def update_progress(self, value: int, message: str): def update_progress(self, value: int, message: str):
"""Update deployment progress.""" """Update deployment progress."""
self.progress_bar.setValue(value) self.progress_bar.setValue(value)
@ -537,6 +566,11 @@ Stage Configurations:
self.deployment_log.append("Connecting to dongles...") self.deployment_log.append("Connecting to dongles...")
self.dongle_status.setText("Initializing dongles...") self.dongle_status.setText("Initializing dongles...")
# Show stop button and hide deploy button
self.stop_button.setEnabled(True)
self.stop_button.setVisible(True)
self.deploy_button.setEnabled(False)
def on_deployment_completed(self, success: bool, message: str): def on_deployment_completed(self, success: bool, message: str):
"""Handle deployment completion.""" """Handle deployment completion."""
self.progress_bar.setValue(100) self.progress_bar.setValue(100)
@ -545,12 +579,18 @@ Stage Configurations:
self.deployment_log.append(f"SUCCESS: {message}") self.deployment_log.append(f"SUCCESS: {message}")
self.status_label.setText("Deployment completed successfully!") self.status_label.setText("Deployment completed successfully!")
self.dongle_status.setText("Pipeline running on dongles") self.dongle_status.setText("Pipeline running on dongles")
# Keep stop button visible for successful deployment
self.stop_button.setEnabled(True)
self.stop_button.setVisible(True)
QMessageBox.information(self, "Deployment Success", message) QMessageBox.information(self, "Deployment Success", message)
else: else:
self.deployment_log.append(f"FAILED: {message}") self.deployment_log.append(f"FAILED: {message}")
self.status_label.setText("Deployment failed") self.status_label.setText("Deployment failed")
# Hide stop button for failed deployment
self.stop_button.setEnabled(False)
self.stop_button.setVisible(False)
self.deploy_button.setEnabled(True) self.deploy_button.setEnabled(True)
self.close_button.setText("Close") self.close_button.setText("Close")
self.progress_bar.setVisible(False) self.progress_bar.setVisible(False)
@ -560,6 +600,9 @@ Stage Configurations:
self.status_label.setText("Deployment failed") self.status_label.setText("Deployment failed")
QMessageBox.critical(self, "Deployment Error", error) QMessageBox.critical(self, "Deployment Error", error)
# Hide stop button and show deploy button on error
self.stop_button.setEnabled(False)
self.stop_button.setVisible(False)
self.deploy_button.setEnabled(True) self.deploy_button.setEnabled(True)
self.close_button.setText("Close") self.close_button.setText("Close")
self.progress_bar.setVisible(False) self.progress_bar.setVisible(False)