Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,28 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
-
from io import BytesIO
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
def generate_image(prompt):
|
| 13 |
-
payload = {
|
| 14 |
-
"inputs": prompt,
|
| 15 |
-
"options": {"wait_for_model": True}
|
| 16 |
-
}
|
| 17 |
-
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 18 |
-
if response.status_code == 200:
|
| 19 |
-
return Image.open(BytesIO(response.content))
|
| 20 |
-
else:
|
| 21 |
-
st.error(f"Error {response.status_code}: {response.text}")
|
| 22 |
-
return None
|
| 23 |
|
| 24 |
# --- Streamlit UI ---
|
| 25 |
-
st.set_page_config(page_title="SD 3.5
|
| 26 |
-
st.title("
|
| 27 |
-
st.
|
| 28 |
-
|
| 29 |
-
# Prompt input
|
| 30 |
-
prompt = st.text_input("Enter your prompt here")
|
| 31 |
|
| 32 |
if st.button("Generate Image") and prompt:
|
| 33 |
-
with st.spinner("Generating
|
| 34 |
-
image =
|
| 35 |
-
|
| 36 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
| 4 |
from PIL import Image
|
|
|
|
| 5 |
|
| 6 |
+
# Load the model locally (first time will auto-download)
|
| 7 |
+
@st.cache_resource
|
| 8 |
+
def load_pipeline():
|
| 9 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 10 |
+
"stabilityai/stable-diffusion-3.5-large",
|
| 11 |
+
torch_dtype=torch.float16,
|
| 12 |
+
variant="fp16",
|
| 13 |
+
)
|
| 14 |
+
pipe = pipe.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 15 |
+
return pipe
|
| 16 |
|
| 17 |
+
pipe = load_pipeline()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# --- Streamlit UI ---
|
| 20 |
+
st.set_page_config(page_title="Local SD 3.5 Generator", page_icon="🧠")
|
| 21 |
+
st.title("🎨 Local Image Generator (SD 3.5)")
|
| 22 |
+
prompt = st.text_input("Enter your prompt here:")
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
if st.button("Generate Image") and prompt:
|
| 25 |
+
with st.spinner("Generating..."):
|
| 26 |
+
image = pipe(prompt).images[0]
|
| 27 |
+
st.image(image, caption="Generated by Stable Diffusion 3.5")
|
| 28 |
+
|