Spaces:
Runtime error
Runtime error
| # import all of the modules you will be using here | |
| # you can import them "as" any alias name for ease | |
| import gradio as gr | |
| # load a model or space here as a variable to use later | |
| my_model = gr.Interface.load("models/runwayml/stable-diffusion-v1-5") | |
| # add a function that will do all the work by defining it here | |
| def my_function(my_input): | |
| # use the loaded model variable to process the input | |
| # this example uses a text-to-image model, so our input will be text, and our output will be an image | |
| my_output = my_model(my_input) | |
| return my_output | |
| # build a user interface using Gradio Blocks | |
| with gr.Blocks() as my_demo: | |
| # a text input box to collect the input | |
| my_input = gr.Textbox(label="Input Text Here") | |
| # a button that will start the process | |
| my_button = gr.Button(label="Run") | |
| # an output Image window to display the returned image | |
| my_output = gr.Image(label="Returned Image") | |
| # a listener to watch for the button to be clicked | |
| # when the button is clicked, it will send the "my_input" text to the "my_function" function, | |
| # and return the output to the "my_output" Image window | |
| my_button.click(my_function, inputs=[my_input], outputs=[my_output]) | |
| # launch the program | |
| my_demo.launch() |