mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
e974cf045c
* guide * fix * Update guides/03_building-with-blocks/04_custom-CSS-and-JS.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/04_custom-CSS-and-JS.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * Update guides/03_building-with-blocks/04_custom-CSS-and-JS.md Co-authored-by: Abubakar Abid <abubakar@huggingface.co> * guide fix * add changeset --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import gradio as gr
|
|
|
|
def welcome(name):
|
|
return f"Welcome to Gradio, {name}!"
|
|
|
|
js = """
|
|
function createGradioAnimation() {
|
|
var container = document.createElement('div');
|
|
container.id = 'gradio-animation';
|
|
container.style.fontSize = '2em';
|
|
container.style.fontWeight = 'bold';
|
|
container.style.textAlign = 'center';
|
|
container.style.marginBottom = '20px';
|
|
|
|
var text = 'Welcome to Gradio!';
|
|
for (var i = 0; i < text.length; i++) {
|
|
(function(i){
|
|
setTimeout(function(){
|
|
var letter = document.createElement('span');
|
|
letter.style.opacity = '0';
|
|
letter.style.transition = 'opacity 0.5s';
|
|
letter.innerText = text[i];
|
|
|
|
container.appendChild(letter);
|
|
|
|
setTimeout(function() {
|
|
letter.style.opacity = '1';
|
|
}, 50);
|
|
}, i * 250);
|
|
})(i);
|
|
}
|
|
|
|
var gradioContainer = document.querySelector('.gradio-container');
|
|
gradioContainer.insertBefore(container, gradioContainer.firstChild);
|
|
|
|
return 'Animation created';
|
|
}
|
|
"""
|
|
with gr.Blocks(js=js) as demo:
|
|
inp = gr.Textbox(placeholder="What is your name?")
|
|
out = gr.Textbox()
|
|
inp.change(welcome, inp, out)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch() |