Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,17 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from diffusers import
|
| 3 |
import torch
|
|
|
|
| 4 |
|
| 5 |
-
st.set_page_config(page_title="Dreamscape Visualizer")
|
| 6 |
-
st.title("Dreamscape Visualizer")
|
| 7 |
|
| 8 |
@st.cache_resource
|
| 9 |
def load_pipeline():
|
| 10 |
-
pipe =
|
| 11 |
-
"
|
| 12 |
-
torch_dtype=torch.float16
|
|
|
|
| 13 |
)
|
| 14 |
pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
return pipe
|
|
@@ -17,21 +19,34 @@ def load_pipeline():
|
|
| 17 |
pipe = load_pipeline()
|
| 18 |
|
| 19 |
style_modifiers = {
|
| 20 |
-
"Fantasy": "
|
| 21 |
-
"Nightmare": "dark horror
|
| 22 |
-
"Lucid": "
|
| 23 |
-
"Sci-Fi": "futuristic
|
| 24 |
-
"Mythical": "
|
| 25 |
}
|
| 26 |
|
| 27 |
-
prompt = st.text_area("Describe your dream:"
|
| 28 |
-
style = st.selectbox("Choose a style:", list(style_modifiers.keys()))
|
| 29 |
|
| 30 |
-
if st.button("
|
| 31 |
if not prompt.strip():
|
| 32 |
-
st.warning("Please
|
| 33 |
else:
|
| 34 |
-
with st.spinner("
|
| 35 |
final_prompt = f"{prompt}, {style_modifiers[style]}"
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 19 |
pipe = load_pipeline()
|
| 20 |
|
| 21 |
style_modifiers = {
|
| 22 |
+
"Fantasy": "fantasy dream, ethereal, colorful",
|
| 23 |
+
"Nightmare": "dark horror dream, creepy surreal",
|
| 24 |
+
"Lucid": "hyperreal dream, bright, vivid",
|
| 25 |
+
"Sci-Fi": "futuristic city, neon dream",
|
| 26 |
+
"Mythical": "mythical world, god-like, celestial"
|
| 27 |
}
|
| 28 |
|
| 29 |
+
prompt = st.text_area("Describe your dream:")
|
| 30 |
+
style = st.selectbox("Choose a dream style:", list(style_modifiers.keys()))
|
| 31 |
|
| 32 |
+
if st.button("Generate Dream Image"):
|
| 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 |
+
)
|