| # This is a simple Gradio app that greets the user and is protected by username and password. | |
| import gradio as gr | |
| # Define a function that takes a name and returns a greeting. | |
| def greet(name): | |
| return "Hello " + name + "!" | |
| # Create a Gradio interface that takes a textbox input, runs it through the greet function, and returns output to a textbox. | |
| demo = gr.Interface(fn=greet, inputs="textbox", outputs="textbox") | |
| # Define the username and password for authentication. | |
| def auth(username, password): | |
| return username == "user" and password == "pass" | |
| # Launch the interface on Hugging Face Spaces with authentication. | |
| demo.launch(share=True, auth=auth, show_error=True) |