Download app.py from Whoruw/Ideface: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/Whoruw/Ideface/resolve/main/app.py
- Command line
-
hf download hf://spaces/Whoruw/Ideface/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Whoruw/Ideface/resolve/main/app.py
1.56 kB
| import torch | |
| from diffusers import StableDiffusionPipeline | |
| import streamlit as st | |
| from PIL import Image | |
| # Load model | |
| model_id = "stabilityai/stable-diffusion-xl-base-1.0" | |
| pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16) | |
| pipe = pipe.to("cuda") | |
| # Streamlit UI | |
| st.title("Stable Diffusion XL Base 1.0 Demo") | |
| st.markdown("## Generate Images with Text Prompts") | |
| # Informational Sidebar | |
| with st.sidebar: | |
| st.header("Instructions") | |
| st.write(""" | |
| 1. Enter a descriptive text prompt. | |
| 2. Select the type of image you want to generate. | |
| 3. Click the "Generate Image" button. | |
| 4. Wait for the image to be generated and displayed. | |
| """) | |
| # Main Interface | |
| prompt = st.text_input("Enter your prompt here:") | |
| image_types = ["Artistic Illustration", "Product Design", "Landscape", "Character", "Photorealistic"] | |
| selected_type = st.selectbox("Select the type of image:", image_types) | |
| # Placeholder for generated image | |
| image_placeholder = st.empty() | |
| if st.button("Generate Image"): | |
| if prompt: | |
| with st.spinner("Generating image..."): | |
| try: | |
| image = pipe(prompt).images[0] | |
| image_placeholder.image(image, caption=f"{selected_type} - {prompt}") | |
| except Exception as e: | |
| st.error(f"An error occurred: {e}") | |
| else: | |
| st.warning("Please enter a prompt to generate an image.") | |
| # Footer | |
| st.markdown(""" | |
| --- | |
| **Stable Diffusion XL Base 1.0** by [Stability AI](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) | |
| """) | |