| # This Gradio app demonstrates how to import a Hugging Face Space and use it within a Gradio interface. | |
| 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") | |
| # Load a Hugging Face Space into the Gradio app. | |
| # Replace 'username/space-name' with the actual username and space name. | |
| # If the Space is private or gated, provide your Hugging Face access token. | |
| space = gr.load(name="username/space-name", src="spaces", hf_token="your-hf-token") | |
| # Combine the Gradio interface and the loaded Space into a single Blocks app. | |
| with gr.Blocks() as combined_app: | |
| with gr.Tab("Greeting"): | |
| demo.render() | |
| with gr.Tab("Space"): | |
| space.render() | |
| # Launch the combined app. | |
| if __name__ == "__main__": | |
| combined_app.launch(show_error=True) |