Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import pipeline | |
| # Initialize the model (example with a text-to-image model) | |
| generator = pipeline("image-generation", model="CompVis/stable-diffusion-v1-4") | |
| # Function to generate an image from a prompt | |
| def generate_image(prompt): | |
| # The pipeline will return a list with the image as the first element | |
| return generator(prompt)[0]["image"] | |
| # Set up the Gradio interface | |
| interface = gr.Interface( | |
| fn=generate_image, # function to be called | |
| inputs="text", # input type: text box for user input (prompt) | |
| outputs="image", # output type: image display | |
| live=True # allows real-time generation (optional) | |
| ) | |
| # Launch the interface | |
| if __name__ == "__main__": | |
| interface.launch() | |