Spaces:
Running
Running
Upload 5 files
Browse files- .gitattributes +1 -0
- README.md +12 -0
- app.py +29 -0
- generated_image.png +3 -0
- generator.py +18 -0
- requirements.txt +7 -0
.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
generated_image.png filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# πΌοΈ AI Image Generator with Stable Diffusion
|
| 2 |
+
|
| 3 |
+
Generate stunning images from text prompts using Stable Diffusion and Streamlit.
|
| 4 |
+
|
| 5 |
+
## π Live Demo
|
| 6 |
+
π [Link to Hugging Face Space](https://huggingface.co/spaces/your-username/image-generator-app)
|
| 7 |
+
|
| 8 |
+
## π¦ Installation
|
| 9 |
+
|
| 10 |
+
```bash
|
| 11 |
+
pip install -r requirements.txt
|
| 12 |
+
streamlit run app.py
|
app.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from generator import generate_image
|
| 4 |
+
|
| 5 |
+
st.set_page_config(page_title="AI Image Generator", layout="centered")
|
| 6 |
+
st.title("π¨ AI Image Generator with Stable Diffusion")
|
| 7 |
+
|
| 8 |
+
st.markdown("Generate high-quality images from text prompts using π€ **Stable Diffusion**.")
|
| 9 |
+
|
| 10 |
+
prompt = st.text_input("π Enter a prompt", value="a scenic view of the Milky Way over mountains")
|
| 11 |
+
|
| 12 |
+
if st.button("Generate Image"):
|
| 13 |
+
with st.spinner("Generating image..."):
|
| 14 |
+
image = generate_image(prompt)
|
| 15 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
| 16 |
+
|
| 17 |
+
# Download option
|
| 18 |
+
img_bytes = image.convert("RGB")
|
| 19 |
+
img_bytes.save("generated_image.png")
|
| 20 |
+
with open("generated_image.png", "rb") as file:
|
| 21 |
+
st.download_button(
|
| 22 |
+
label="π₯ Download Image",
|
| 23 |
+
data=file,
|
| 24 |
+
file_name="generated_image.png",
|
| 25 |
+
mime="image/png"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
st.markdown("---")
|
| 29 |
+
st.markdown("Made with β€οΈ using [Hugging Face π€](https://huggingface.co/) and [Streamlit](https://streamlit.io/)")
|
generated_image.png
ADDED
|
Git LFS Details
|
generator.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from diffusers import StableDiffusionPipeline
|
| 2 |
+
import torch
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
@st.cache_resource
|
| 6 |
+
def load_pipeline():
|
| 7 |
+
model_id = "runwayml/stable-diffusion-v1-5"
|
| 8 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 9 |
+
model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32
|
| 10 |
+
)
|
| 11 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 12 |
+
pipe = pipe.to(device)
|
| 13 |
+
return pipe
|
| 14 |
+
|
| 15 |
+
def generate_image(prompt):
|
| 16 |
+
pipe = load_pipeline()
|
| 17 |
+
image = pipe(prompt).images[0]
|
| 18 |
+
return image
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
diffusers
|
| 3 |
+
transformers
|
| 4 |
+
streamlit
|
| 5 |
+
accelerate
|
| 6 |
+
safetensors
|
| 7 |
+
Pillow
|