MaroofTechSorcerer commited on
Commit
68233c3
Β·
verified Β·
1 Parent(s): b9f4800

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -1,18 +1,17 @@
1
  import streamlit as st
2
- from diffusers import StableDiffusionXLPipeline
3
  import torch
4
  from io import BytesIO
5
 
6
- st.set_page_config(page_title="Dreamscape Visualizer (HD)")
7
- st.title("🌌 Dreamscape Visualizer – High Quality")
8
 
9
  @st.cache_resource
10
  def load_pipeline():
11
- pipe = StableDiffusionXLPipeline.from_pretrained(
12
- "stabilityai/stable-diffusion-xl-base-1.0",
13
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
14
- variant="fp16" if torch.cuda.is_available() else None,
15
- use_safetensors=True
16
  )
17
  pipe.to("cuda" if torch.cuda.is_available() else "cpu")
18
  return pipe
@@ -34,19 +33,20 @@ if st.button("Generate Dream Image"):
34
  if not prompt.strip():
35
  st.warning("Please describe your dream first!")
36
  else:
37
- with st.spinner("Generating your high-res dream..."):
38
  final_prompt = f"{prompt}, {style_modifiers[style]}"
39
- result = pipe(prompt=final_prompt, guidance_scale=7.5, num_inference_steps=30)
40
  image = result.images[0]
41
- st.image(image, caption="✨ Your Dream Visualized in HD", use_column_width=True)
42
 
43
- # Download Button
44
  buf = BytesIO()
45
  image.save(buf, format="PNG")
46
  byte_im = buf.getvalue()
 
47
  st.download_button(
48
  label="πŸ“₯ Download Dream Image",
49
  data=byte_im,
50
- file_name="dreamscape_hd.png",
51
  mime="image/png"
52
  )
 
1
  import streamlit as st
2
+ from diffusers import AutoPipelineForText2Image
3
  import torch
4
  from io import BytesIO
5
 
6
+ st.set_page_config(page_title="Dreamscape Visualizer (Turbo)")
7
+ st.title("🌌 Dreamscape Visualizer (Fast Mode)")
8
 
9
  @st.cache_resource
10
  def load_pipeline():
11
+ pipe = AutoPipelineForText2Image.from_pretrained(
12
+ "stabilityai/sdxl-turbo",
13
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
14
+ variant="fp16" if torch.cuda.is_available() else None
 
15
  )
16
  pipe.to("cuda" if torch.cuda.is_available() else "cpu")
17
  return pipe
 
33
  if not prompt.strip():
34
  st.warning("Please describe your dream first!")
35
  else:
36
+ with st.spinner("Dreaming up your world..."):
37
  final_prompt = f"{prompt}, {style_modifiers[style]}"
38
+ result = pipe(prompt=final_prompt, guidance_scale=0.0, num_inference_steps=2)
39
  image = result.images[0]
40
+ st.image(image, caption="✨ Your Dream Visualized", use_column_width=True)
41
 
42
+ # Convert image to bytes for download
43
  buf = BytesIO()
44
  image.save(buf, format="PNG")
45
  byte_im = buf.getvalue()
46
+
47
  st.download_button(
48
  label="πŸ“₯ Download Dream Image",
49
  data=byte_im,
50
+ file_name="dreamscape.png",
51
  mime="image/png"
52
  )