Muthuraja18 commited on
Commit
fa04d55
·
verified ·
1 Parent(s): 855c0dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -1,34 +1,34 @@
1
  import streamlit as st
2
- from diffusers import StableDiffusionPipeline
3
  import torch
4
  from PIL import Image
5
  import io
6
  import os
7
 
8
- # Force CPU usage on Spaces
9
  os.environ["CUDA_VISIBLE_DEVICES"] = ""
10
 
11
  @st.cache_resource
12
  def load_model():
13
- pipe = StableDiffusionPipeline.from_pretrained(
14
- "runwayml/stable-diffusion-v1-5",
15
- torch_dtype=torch.float32,
16
  )
17
- pipe.to("cpu") # Force CPU usage
18
  return pipe
19
 
20
- # Streamlit UI
21
- st.title("🎨 AI Image Generator (CPU - Hugging Face Spaces)")
22
 
23
  prompt = st.text_input("Enter your prompt:",
24
- "A multi-dimensional futuristic city with glowing lights, fractals, 8K")
25
 
26
- guidance = st.slider("Creativity (Guidance Scale)", 1.0, 20.0, 7.5)
27
 
28
- if st.button("Generate"):
29
- with st.spinner("Generating image on CPU... please wait ⏳"):
30
  pipe = load_model()
31
- image = pipe(prompt, guidance_scale=guidance).images[0]
 
32
 
33
  st.image(image, caption="Generated Image", use_column_width=True)
34
 
 
1
  import streamlit as st
2
+ from diffusers import AutoPipelineForText2Image
3
  import torch
4
  from PIL import Image
5
  import io
6
  import os
7
 
8
+ # Force CPU usage
9
  os.environ["CUDA_VISIBLE_DEVICES"] = ""
10
 
11
  @st.cache_resource
12
  def load_model():
13
+ pipe = AutoPipelineForText2Image.from_pretrained(
14
+ "stabilityai/sd-turbo",
15
+ torch_dtype=torch.float32 # CPU-compatible
16
  )
17
+ pipe.to("cpu")
18
  return pipe
19
 
20
+ st.title("⚡ Fast AI Image Generator (under 1 minute)")
 
21
 
22
  prompt = st.text_input("Enter your prompt:",
23
+ "A glowing alien city with floating islands and neon rivers, concept art, 8K")
24
 
25
+ guidance = st.slider("Guidance scale (higher = more faithful to prompt)", 1.0, 10.0, 3.0)
26
 
27
+ if st.button("Generate Image"):
28
+ with st.spinner("Generating image (approx. 20–40 seconds on CPU)..."):
29
  pipe = load_model()
30
+ result = pipe(prompt, guidance_scale=guidance, num_inference_steps=20)
31
+ image = result.images[0]
32
 
33
  st.image(image, caption="Generated Image", use_column_width=True)
34