| import gradio as gr | |
| def greet(name): | |
| return "Hello " + name + "!" | |
| def another_endpoint(text): | |
| return f"You said: {text}" | |
| with gr.Blocks() as iface: | |
| name_input = gr.Textbox(label="Enter your name") | |
| output = gr.Textbox(label="Greeting") | |
| greet_button = gr.Button("Greet") | |
| greet_button.click(greet, inputs=name_input, outputs=output, api_name="/greet") | |
| text_input = gr.Textbox(label="Enter some text") | |
| text_output = gr.Textbox(label="Echo") | |
| echo_button = gr.Button("Echo") | |
| echo_button.click(another_endpoint, inputs=text_input, outputs=text_output, api_name="/echo") | |
| if __name__ == "__main__": | |
| iface.launch(share=True) |