File size: 907 Bytes
bd4bf8c
396f1de
 
7168107
 
 
 
 
 
bd4bf8c
54c37d5
bd4bf8c
396f1de
 
 
 
 
 
7168107
396f1de
bd4bf8c
396f1de
bd4bf8c
396f1de
 
bd4bf8c
396f1de
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
from diffusers import StableDiffusionPipeline
import torch
import os

# Set cache to writable directory
os.environ["HF_HOME"] = "/tmp"
os.environ["TRANSFORMERS_CACHE"] = "/tmp"
os.environ["HF_HUB_CACHE"] = "/tmp"

st.set_page_config(page_title="AI Design Generator", layout="centered")

@st.cache_resource
def load_model():
    model = StableDiffusionPipeline.from_pretrained(
        "runwayml/stable-diffusion-v1-5", 
        torch_dtype=torch.float32
    )
    model.to("cpu")  # CPU unless GPU enabled in Space settings
    return model

pipe = load_model()

st.title("🧠 AI Design Generator")
prompt = st.text_input("Enter your design prompt", "a modern packaging design with bright colors")

if st.button("Generate Image"):
    with st.spinner("Generating..."):
        image = pipe(prompt).images[0]
        st.image(image, caption="Generated Design", use_column_width=True)