Spaces:
Runtime error
Runtime error
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +17 -18
src/streamlit_app.py
CHANGED
|
@@ -1,27 +1,26 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
from io import BytesIO
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
st.set_page_config(page_title="AI Design Generator", layout="centered")
|
| 8 |
-
st.title("🎨 AI Poster/Packaging Design Generator")
|
| 9 |
-
st.write("Enter a prompt to generate your custom design:")
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
with st.spinner("Generating..."):
|
| 15 |
-
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-2"
|
| 16 |
-
headers = {"Authorization": f"Bearer {os.environ['HF_TOKEN']}"}
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
st.error("Failed to generate image. Try again later.")
|
| 26 |
|
| 27 |
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
|
|
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="AI Design Generator", layout="centered")
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_model():
|
| 9 |
+
model = StableDiffusionPipeline.from_pretrained(
|
| 10 |
+
"runwayml/stable-diffusion-v1-5",
|
| 11 |
+
torch_dtype=torch.float32
|
| 12 |
+
)
|
| 13 |
+
model.to("cpu") # Space is on CPU unless you enable GPU manually
|
| 14 |
+
return model
|
| 15 |
|
| 16 |
+
pipe = load_model()
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
+
st.title("🧠 AI Design Generator")
|
| 19 |
+
prompt = st.text_input("Enter your design prompt", "a modern packaging design with bright colors")
|
| 20 |
|
| 21 |
+
if st.button("Generate Image"):
|
| 22 |
+
with st.spinner("Generating..."):
|
| 23 |
+
image = pipe(prompt).images[0]
|
| 24 |
+
st.image(image, caption="Generated Design", use_column_width=True)
|
|
|
|
| 25 |
|
| 26 |
|