Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -116,50 +116,49 @@ def add_gallery(image, model_str, gallery):
|
|
| 116 |
js="""
|
| 117 |
<script>
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
const
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
a.click();
|
| 126 |
-
document.body.removeChild(a);
|
| 127 |
-
};
|
| 128 |
-
|
| 129 |
-
// Monitor image changes
|
| 130 |
-
const monitorImageChange = (imageElement) => {
|
| 131 |
-
if (!(imageElement instanceof HTMLImageElement)) {
|
| 132 |
-
console.error('The provided element is not an image.');
|
| 133 |
-
return;
|
| 134 |
}
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
|
| 139 |
-
|
| 140 |
-
|
|
|
|
| 141 |
}
|
| 142 |
});
|
| 143 |
});
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
});
|
|
|
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
// Start monitoring after page load
|
| 154 |
-
window.addEventListener('load', () => {
|
| 155 |
-
const img = document.querySelector('svelte-1pijsyv'); // Select the target image element
|
| 156 |
-
if (img) {
|
| 157 |
-
monitorImageChange(img);
|
| 158 |
-
} else {
|
| 159 |
-
console.error('No image found to monitor.');
|
| 160 |
-
}
|
| 161 |
-
});
|
| 162 |
|
|
|
|
| 163 |
|
| 164 |
</script>
|
| 165 |
"""
|
|
@@ -187,7 +186,7 @@ with gr.Blocks(fill_width=True, head=js) as demo:
|
|
| 187 |
with gr.Column(scale=1):
|
| 188 |
with gr.Group():
|
| 189 |
with gr.Row():
|
| 190 |
-
output = [gr.Image(label=m, show_download_button=True,
|
| 191 |
interactive=False, width=112, height=112, show_share_button=False, format="png",
|
| 192 |
visible=True) for m in default_models]
|
| 193 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
|
|
|
| 116 |
js="""
|
| 117 |
<script>
|
| 118 |
|
| 119 |
+
/*
|
| 120 |
+
function simulateButtonPress_() {
|
| 121 |
+
const button = document.getElementById('simulate-button');
|
| 122 |
+
if (button) {
|
| 123 |
+
button.click(); // Simulate the button press
|
| 124 |
+
console.log('Button Pressed!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
}
|
| 126 |
+
}
|
| 127 |
+
*/
|
| 128 |
|
| 129 |
+
function simulateButtonPress() {
|
| 130 |
+
console.log('Button Pressed!');
|
| 131 |
+
}
|
| 132 |
+
|
| 133 |
+
// Function to observe image changes
|
| 134 |
+
function observeImageChanges() {
|
| 135 |
+
// Select all images with the 'image-monitor' class
|
| 136 |
+
const images = document.querySelectorAll('.image-monitor');
|
| 137 |
+
|
| 138 |
+
// Create a MutationObserver to watch for changes in the image src
|
| 139 |
+
const observer = new MutationObserver((mutationsList, observer) => {
|
| 140 |
+
mutationsList.forEach(mutation => {
|
| 141 |
if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
|
| 142 |
+
// If the image src changes, simulate button press
|
| 143 |
+
console.log('Image changed!');
|
| 144 |
+
simulateButtonPress();
|
| 145 |
}
|
| 146 |
});
|
| 147 |
});
|
| 148 |
+
|
| 149 |
+
// Observer options: observe changes to attributes (like src)
|
| 150 |
+
const config = { attributes: true };
|
| 151 |
|
| 152 |
+
// Start observing each image
|
| 153 |
+
images.forEach(image => {
|
| 154 |
+
observer.observe(image, config);
|
| 155 |
});
|
| 156 |
+
}
|
| 157 |
|
| 158 |
+
// Start observing
|
| 159 |
+
observeImageChanges();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 160 |
|
| 161 |
+
console.log("Yo");
|
| 162 |
|
| 163 |
</script>
|
| 164 |
"""
|
|
|
|
| 186 |
with gr.Column(scale=1):
|
| 187 |
with gr.Group():
|
| 188 |
with gr.Row():
|
| 189 |
+
output = [gr.Image(label=m, show_download_button=True, elem_classes="image-monitor",
|
| 190 |
interactive=False, width=112, height=112, show_share_button=False, format="png",
|
| 191 |
visible=True) for m in default_models]
|
| 192 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|