File size: 1,253 Bytes
5456b48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st 
from diffusers import StableDiffusionPipeline 
import torch

st.set_page_config(page_title="Dreamscape Visualizer") 
st.title("Dreamscape Visualizer")

@st.cache_resource 
def load_pipeline(): 
    pipe = StableDiffusionPipeline.from_pretrained( 
        "runwayml/stable-diffusion-v1-5", 
        torch_dtype=torch.float16 
    ) 
    pipe.to("cuda" if torch.cuda.is_available() else "cpu") 
    return pipe

pipe = load_pipeline() 
style_modifiers = { 
    "Fantasy": "dreamlike fantasy art", 
    "Nightmare": "dark horror surrealism", 
    "Lucid": "vivid hyperreal dreamscape", 
    "Sci-Fi": "futuristic dream world", 
    "Mythical": "ancient mythical surrealism" 
}  

prompt = st.text_area("Describe your dream:", height=100) 
style = st.selectbox("Choose a style:", list(style_modifiers.keys())) 
    if st.button("Visualize Dream"): 
        if not prompt.strip(): 
            st.warning("Please enter a dream description.") 
        else: 
            with st.spinner("Generating your dreamscape..."): 
                final_prompt = f"{prompt}, {style_modifiers[style]}" 
                image = pipe(final_prompt).images[0]
                st.image(image, caption="Here is your dreamscape!",use_column_width=True)