Spaces:
Runtime error
Runtime error
Download app.py from dalexandre/trials_class_1: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/dalexandre/trials_class_1/resolve/main/app.py
- Command line
-
hf download hf://spaces/dalexandre/trials_class_1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/dalexandre/trials_class_1/resolve/main/app.py
1.13 kB
| import gradio as gr | |
| from diffusers import StableDiffusionPipeline | |
| def generate_image(prompt): | |
| # Load the pre-trained Stable Diffusion model from Hugging Face | |
| pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", | |
| revision="fp16", | |
| torch_dtype=torch.float16, | |
| use_auth_token=True) # You need your Hugging Face token here | |
| pipe = pipe.to("cuda") # Use GPU if available | |
| # Generate the image based on the prompt | |
| image = pipe(prompt).images[0] | |
| # Convert image to display it with Gradio | |
| return image | |
| # Create the Gradio interface | |
| iface = gr.Interface(fn=generate_image, | |
| inputs=gr.Textbox(lines=2, placeholder="Enter your prompt here..."), | |
| outputs="image", | |
| title="Stable Diffusion Text-to-Image Generator", | |
| description="This app uses Stable Diffusion to generate images based on your text prompts.") | |
| # Run the Gradio app | |
| iface.launch() | |