Spaces:
Sleeping
Sleeping
Download app.py from sushann222/text2image: direct link, hf CLI and curl.
- Browser
- Download file 701 Bytes
-
https://huggingface.co/spaces/sushann222/text2image/resolve/main/app.py
- Command line
-
hf download hf://spaces/sushann222/text2image/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sushann222/text2image/resolve/main/app.py
701 Bytes
| import torch | |
| from diffusers import StableDiffusionPipeline | |
| import streamlit as st | |
| st.title("Text to Image Generation") | |
| # Load the diffusion model | |
| pipe = StableDiffusionPipeline.from_pretrained( | |
| "dreamlike-art/dreamlike-photoreal-2.0", | |
| torch_dtype=torch.float32, | |
| use_safetensors=True, | |
| low_cpu_mem_usage=True | |
| ).to("cpu") | |
| st.success("Model loaded successfully.") | |
| # Enter a discription | |
| prompt = st.text_input("Enter your image description:") | |
| if st.button("Generate image"): | |
| if prompt: # check user enter prompt | |
| image = pipe(prompt, num_inference_steps=30).images[0] | |
| st.image(image, caption="Generated Image") | |
| else: | |
| st.warning("Please enter a prompt.") | |