Spaces:
Configuration error
Configuration error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.")
|