rynmurdock multimodalart HF staff commited on
Commit
ecec1ba
1 Parent(s): b1772c8

Firing buttons with colors (#3)

Browse files

- Firing buttons with colors (563b65224962a273f4023dbd7e5793285eb8de1c)
- Update app.py (01006ae7e5c0f2c7d597de9dc58be4ebc591a784)
- Update app.py (c6b69d9c65ecd6f243973db46141ba393cb7076b)


Co-authored-by: Apolinário from multimodal AI art <multimodalart@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -162,8 +162,17 @@ css = '''.gradio-container{max-width: 700px !important}
162
  #description{text-align: center}
163
  #description h1{display: block}
164
  #description p{margin-top: 0}
 
 
 
 
 
 
 
 
 
165
  '''
166
- js = '''
167
  <script>
168
  document.addEventListener('keydown', function(event) {
169
  if (event.key === 'a' || event.key === 'A') {
@@ -177,10 +186,30 @@ document.addEventListener('keydown', function(event) {
177
  document.getElementById('like').click();
178
  }
179
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  </script>
181
  '''
182
 
183
- with gr.Blocks(css=css, head=js) as demo:
184
  gr.Markdown('''# Generative Recommenders
185
  Explore the latent space without text prompts, based on your preferences. [Learn more on the blog](https://rynmurdock.github.io/posts/2024/3/generative_recomenders/)
186
  ''', elem_id="description")
 
162
  #description{text-align: center}
163
  #description h1{display: block}
164
  #description p{margin-top: 0}
165
+ .fade-in-out {animation: fadeInOut 3s forwards}
166
+ @keyframes fadeInOut {
167
+ 0% {
168
+ background: var(--bg-color);
169
+ }
170
+ 100% {
171
+ background: var(--button-secondary-background-fill);
172
+ }
173
+ }
174
  '''
175
+ js_head = '''
176
  <script>
177
  document.addEventListener('keydown', function(event) {
178
  if (event.key === 'a' || event.key === 'A') {
 
186
  document.getElementById('like').click();
187
  }
188
  });
189
+ function fadeInOut(button, color) {
190
+ button.style.setProperty('--bg-color', color);
191
+ button.classList.remove('fade-in-out');
192
+ void button.offsetWidth; // This line forces a repaint by accessing a DOM property
193
+
194
+ button.classList.add('fade-in-out');
195
+ button.addEventListener('animationend', () => {
196
+ button.classList.remove('fade-in-out'); // Reset the animation state
197
+ }, {once: true});
198
+ }
199
+ document.body.addEventListener('click', function(event) {
200
+ const target = event.target;
201
+ if (target.id === 'dislike') {
202
+ fadeInOut(target, '#ff1717');
203
+ } else if (target.id === 'like') {
204
+ fadeInOut(target, '#006500');
205
+ } else if (target.id === 'neither') {
206
+ fadeInOut(target, '#cccccc');
207
+ }
208
+ });
209
  </script>
210
  '''
211
 
212
+ with gr.Blocks(css=css, head=js_head) as demo:
213
  gr.Markdown('''# Generative Recommenders
214
  Explore the latent space without text prompts, based on your preferences. [Learn more on the blog](https://rynmurdock.github.io/posts/2024/3/generative_recomenders/)
215
  ''', elem_id="description")