Skip to content

Commit

Permalink
🎨 Auto enable unit on image upload (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Jun 25, 2023
1 parent 0b7f431 commit 95b0079
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions javascript/active_units.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ onUiUpdate(() => {
class GradioTab {
constructor(tab) {
this.enabledCheckbox = tab.querySelector('.cnet-unit-enabled input');
this.inputImage = tab.querySelector('.cnet-input-image-group .cnet-image input[type="file"]');
const tabs = tab.parentNode;
this.tabNav = tabs.querySelector('.tab-nav');
this.tabIndex = childIndex(tab) - 1; // -1 because tab-nav is also at the same level.

this.attachEnabledButtonListener();
this.attachTabNavChangeObserver();
this.attachImageUploadListener();
}

getTabNavButton() {
Expand Down Expand Up @@ -63,6 +65,14 @@ onUiUpdate(() => {
});
observer.observe(this.tabNav, { childList: true });
}

attachImageUploadListener() {
this.inputImage.addEventListener('change', (event) => {
if (!event.target.files) return;
if (!this.enabledCheckbox.checked)
this.enabledCheckbox.click();
});
}
}

gradioApp().querySelectorAll('.cnet-unit-tab').forEach(tab => {
Expand Down

0 comments on commit 95b0079

Please sign in to comment.