File size: 1,876 Bytes
68e60cb
57d56f8
5456b48
40f02f9
5456b48
57d56f8
 
5456b48
68e60cb
 
57d56f8
 
40f02f9
57d56f8
 
68e60cb
 
5456b48
 
68e60cb
5456b48
68e60cb
40f02f9
 
 
 
 
68e60cb
 
40f02f9
 
68e60cb
40f02f9
68e60cb
40f02f9
68e60cb
57d56f8
68e60cb
57d56f8
40f02f9
57d56f8
40f02f9
57d56f8
40f02f9
 
 
 
 
 
57d56f8
40f02f9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
from diffusers import StableDiffusionXLPipeline
import torch
from io import BytesIO

st.set_page_config(page_title="Dreamscape Visualizer (HD)")
st.title("🌌 Dreamscape Visualizer – High Quality")

@st.cache_resource
def load_pipeline():
    pipe = StableDiffusionXLPipeline.from_pretrained(
        "stabilityai/stable-diffusion-xl-base-1.0",
        torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
        variant="fp16" if torch.cuda.is_available() else None,
        use_safetensors=True
    )
    pipe.to("cuda" if torch.cuda.is_available() else "cpu")
    return pipe

pipe = load_pipeline()

style_modifiers = {
    "Fantasy": "fantasy dream, ethereal, colorful",
    "Nightmare": "dark horror dream, creepy surreal",
    "Lucid": "hyperreal dream, bright, vivid",
    "Sci-Fi": "futuristic city, neon dream",
    "Mythical": "mythical world, god-like, celestial"
}

prompt = st.text_area("Describe your dream:")
style = st.selectbox("Choose a dream style:", list(style_modifiers.keys()))

if st.button("Generate Dream Image"):
    if not prompt.strip():
        st.warning("Please describe your dream first!")
    else:
        with st.spinner("Generating your high-res dream..."):
            final_prompt = f"{prompt}, {style_modifiers[style]}"
            result = pipe(prompt=final_prompt, guidance_scale=7.5, num_inference_steps=30)
            image = result.images[0]
            st.image(image, caption="✨ Your Dream Visualized in HD", use_column_width=True)

            # Download Button
            buf = BytesIO()
            image.save(buf, format="PNG")
            byte_im = buf.getvalue()
            st.download_button(
                label="πŸ“₯ Download Dream Image",
                data=byte_im,
                file_name="dreamscape_hd.png",
                mime="image/png"
            )