nimra-mughal commited on
Commit
396f1de
·
verified ·
1 Parent(s): 6ad0538

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +17 -18
src/streamlit_app.py CHANGED
@@ -1,27 +1,26 @@
1
  import streamlit as st
2
- import requests
3
- from PIL import Image
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
- prompt = st.text_input("Prompt", "modern minimalist packaging with red and white theme")
 
 
 
 
 
 
 
12
 
13
- if st.button("Generate Design"):
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
- payload = {"inputs": prompt}
19
- response = requests.post(API_URL, headers=headers, json=payload)
20
 
21
- if response.status_code == 200:
22
- image = Image.open(BytesIO(response.content))
23
- st.image(image, caption="Generated Design")
24
- else:
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