Uthar commited on
Commit
54b0d06
1 Parent(s): b03fd10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -1
app.py CHANGED
@@ -114,7 +114,42 @@ def add_gallery(image, model_str, gallery):
114
  return gallery
115
 
116
  js="""
117
- <script>console.log("BOOOOOOOOOOOOOOOOBS");</script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  """
119
 
120
  with gr.Blocks(fill_width=True, head=js) as demo:
 
114
  return gallery
115
 
116
  js="""
117
+ <script>
118
+
119
+ downloadImage = (url, filename) => {
120
+ const a = document.createElement('a');
121
+ a.href = url;
122
+ a.download = filename || 'image.jpg';
123
+ document.body.appendChild(a);
124
+ a.click();
125
+ document.body.removeChild(a);
126
+ };
127
+
128
+ // Monitor image changes
129
+ const monitorImageChange = (imageElement) => {
130
+ if (!(imageElement instanceof HTMLImageElement)) {
131
+ console.error('The provided element is not an image.');
132
+ return;
133
+ }
134
+
135
+ const observer = new MutationObserver((mutationsList) => {
136
+ mutationsList.forEach((mutation) => {
137
+ if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
138
+ console.log('Image source changed:', imageElement.src);
139
+ downloadImage(imageElement.src, 'downloaded_image.jpg');
140
+ }
141
+ });
142
+ });
143
+
144
+ observer.observe(imageElement, {
145
+ attributes: true, // Look for attribute changes
146
+ attributeFilter: ['src'], // Only watch for 'src' changes
147
+ });
148
+
149
+ console.log('Now monitoring image changes for:', imageElement);
150
+ };
151
+
152
+ </script>
153
  """
154
 
155
  with gr.Blocks(fill_width=True, head=js) as demo: