chawitzoon commited on
Commit
d33dfcc
·
verified ·
1 Parent(s): 136f2ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -20
app.py CHANGED
@@ -296,28 +296,49 @@ def process_lyrics(lyrics: str, song_name: str = "", artist_name: str = ""):
296
  return display_html, youtube_embed, "Click on a word to get its definition."
297
 
298
 
299
- # Define the Gradio interface
300
- with gr.Blocks(js="""
301
- function attach_click_listeners() {
302
- const clickableWords = document.querySelectorAll('.clickable-word');
303
- const hiddenInput = document.getElementById('hidden_json_input');
304
-
305
- clickableWords.forEach(wordSpan => {
306
- wordSpan.addEventListener('click', function() {
307
- const word = this.dataset.word;
308
- const lang = this.dataset.lang;
309
-
310
- const data = { word: word, lang: lang };
311
- hiddenInput.value = JSON.stringify(data);
312
-
313
- // Trigger the 'input' event to notify Gradio
314
- const event = new Event('input', { bubbles: true });
315
- hiddenInput.dispatchEvent(event);
316
- });
317
- });
 
 
 
 
 
 
 
 
 
318
  }
319
- """) as demo:
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  # This is the hidden component that our JavaScript will update.
322
  # The `elem_id` is crucial for the JS to find it.
323
  hidden_json_input = gr.Textbox(visible=False, elem_id="hidden_json_input")
 
296
  return display_html, youtube_embed, "Click on a word to get its definition."
297
 
298
 
299
+ def welcome(name):
300
+ return f"Welcome to Gradio, {name}!"
301
+
302
+ js = """
303
+ function createGradioAnimation() {
304
+ var container = document.createElement('div');
305
+ container.id = 'gradio-animation';
306
+ container.style.fontSize = '2em';
307
+ container.style.fontWeight = 'bold';
308
+ container.style.textAlign = 'center';
309
+ container.style.marginBottom = '20px';
310
+
311
+ var text = 'Welcome to Gradio!';
312
+ for (var i = 0; i < text.length; i++) {
313
+ (function(i){
314
+ setTimeout(function(){
315
+ var letter = document.createElement('span');
316
+ letter.style.opacity = '0';
317
+ letter.style.transition = 'opacity 0.5s';
318
+ letter.innerText = text[i];
319
+
320
+ container.appendChild(letter);
321
+
322
+ setTimeout(function() {
323
+ letter.style.opacity = '1';
324
+ }, 50);
325
+ }, i * 250);
326
+ })(i);
327
  }
 
328
 
329
+ var gradioContainer = document.querySelector('.gradio-container');
330
+ gradioContainer.insertBefore(container, gradioContainer.firstChild);
331
+
332
+ return 'Animation created';
333
+ }
334
+ """
335
+
336
+ # Define the Gradio interface
337
+ with gr.Blocks(js=js) as demo:
338
+
339
+ inp = gr.Textbox(placeholder="What is your name?")
340
+ out = gr.Textbox()
341
+ inp.change(welcome, inp, out)
342
  # This is the hidden component that our JavaScript will update.
343
  # The `elem_id` is crucial for the JS to find it.
344
  hidden_json_input = gr.Textbox(visible=False, elem_id="hidden_json_input")