MaroofTechSorcerer's picture
Update app.py
57d56f8 verified
raw
history blame
1.88 kB
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"
)