Update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,17 @@
|
|
1 |
import streamlit as st
|
2 |
-
from diffusers import
|
3 |
import torch
|
4 |
from io import BytesIO
|
5 |
|
6 |
-
st.set_page_config(page_title="Dreamscape Visualizer (
|
7 |
-
st.title("π Dreamscape Visualizer
|
8 |
|
9 |
@st.cache_resource
|
10 |
def load_pipeline():
|
11 |
-
pipe =
|
12 |
-
"stabilityai/
|
13 |
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
14 |
-
variant="fp16" if torch.cuda.is_available() else None
|
15 |
-
use_safetensors=True
|
16 |
)
|
17 |
pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
18 |
return pipe
|
@@ -34,19 +33,20 @@ if st.button("Generate Dream Image"):
|
|
34 |
if not prompt.strip():
|
35 |
st.warning("Please describe your dream first!")
|
36 |
else:
|
37 |
-
with st.spinner("
|
38 |
final_prompt = f"{prompt}, {style_modifiers[style]}"
|
39 |
-
result = pipe(prompt=final_prompt, guidance_scale=
|
40 |
image = result.images[0]
|
41 |
-
st.image(image, caption="β¨ Your Dream Visualized
|
42 |
|
43 |
-
#
|
44 |
buf = BytesIO()
|
45 |
image.save(buf, format="PNG")
|
46 |
byte_im = buf.getvalue()
|
|
|
47 |
st.download_button(
|
48 |
label="π₯ Download Dream Image",
|
49 |
data=byte_im,
|
50 |
-
file_name="
|
51 |
mime="image/png"
|
52 |
)
|
|
|
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
|
|
|
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 |
)
|