|
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) |