import gradio as gr | |
# 自定义 HTML 和 JavaScript 代码 | |
custom_html = """ | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Custom JavaScript</title> | |
</head> | |
<body> | |
<button id="myButton">Click me</button> | |
<script> | |
document.getElementById("myButton").addEventListener("click", function() { | |
alert("Button clicked!"); | |
}); | |
</script> | |
</body> | |
</html> | |
""" | |
def greet(name): | |
return "Hello " + name + "!" | |
# 创建 Gradio 应用,嵌入自定义 HTML | |
with gr.Blocks() as demo: | |
custom_component = gr.HTML(custom_html) | |
gr.Interface(fn=greet, inputs="text", outputs="text") | |
demo.launch() | |