Rajeev91691 commited on
Commit
f767ce3
Β·
verified Β·
1 Parent(s): 1f7303e

Upload 5 files

Browse files
Files changed (6) hide show
  1. .gitattributes +1 -0
  2. README.md +12 -0
  3. app.py +29 -0
  4. generated_image.png +3 -0
  5. generator.py +18 -0
  6. 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

  • SHA256: a846f6abbb123ef5c32ce1126ef29fb8f670982518254cb0701c1046a54f3294
  • Pointer size: 131 Bytes
  • Size of remote file: 523 kB
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