Spaces:
Runtime error
Runtime error
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,25 +2,21 @@ from diffusers import StableDiffusionPipeline
|
|
| 2 |
import torch
|
| 3 |
from PIL import Image
|
| 4 |
import streamlit as st
|
| 5 |
-
import sys
|
| 6 |
-
print(sys.version)
|
| 7 |
-
|
| 8 |
|
| 9 |
# Load the Stable Diffusion pipeline
|
| 10 |
@st.cache(allow_output_mutation=True)
|
| 11 |
def load_pipeline():
|
| 12 |
pipeline = StableDiffusionPipeline.from_pretrained(
|
| 13 |
-
"CompVis/stable-diffusion-v1-4",
|
| 14 |
-
torch_dtype=torch.float32 #
|
| 15 |
)
|
| 16 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 17 |
pipeline.to(device)
|
| 18 |
return pipeline
|
| 19 |
|
| 20 |
-
|
| 21 |
def main():
|
| 22 |
st.title("Stable Diffusion Image Generator")
|
| 23 |
-
st.write("Generate images from text prompts using Stable Diffusion
|
| 24 |
|
| 25 |
# Initialize the pipeline
|
| 26 |
pipeline = load_pipeline()
|
|
@@ -29,19 +25,18 @@ def main():
|
|
| 29 |
prompt = st.text_input("Enter your text prompt", "")
|
| 30 |
|
| 31 |
# Generate button
|
| 32 |
-
if st.button("Generate"):
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
if __name__ == "__main__":
|
| 47 |
-
main()
|
|
|
|
| 2 |
import torch
|
| 3 |
from PIL import Image
|
| 4 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Load the Stable Diffusion pipeline
|
| 7 |
@st.cache(allow_output_mutation=True)
|
| 8 |
def load_pipeline():
|
| 9 |
pipeline = StableDiffusionPipeline.from_pretrained(
|
| 10 |
+
"CompVis/stable-diffusion-v1-4",
|
| 11 |
+
torch_dtype=torch.float32 # Use float32 for CPU support
|
| 12 |
)
|
| 13 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 14 |
pipeline.to(device)
|
| 15 |
return pipeline
|
| 16 |
|
|
|
|
| 17 |
def main():
|
| 18 |
st.title("Stable Diffusion Image Generator")
|
| 19 |
+
st.write("Generate images from text prompts using Stable Diffusion")
|
| 20 |
|
| 21 |
# Initialize the pipeline
|
| 22 |
pipeline = load_pipeline()
|
|
|
|
| 25 |
prompt = st.text_input("Enter your text prompt", "")
|
| 26 |
|
| 27 |
# Generate button
|
| 28 |
+
if st.button("Generate"):
|
| 29 |
+
if not prompt:
|
| 30 |
+
st.warning("Please enter a prompt first.")
|
| 31 |
+
return # ✅ Fixed indentation
|
| 32 |
|
| 33 |
+
st.write("Generating your image...")
|
| 34 |
+
with torch.no_grad():
|
| 35 |
+
result = pipeline(prompt)
|
| 36 |
+
image = result.images[0] # Extract the generated image
|
| 37 |
|
| 38 |
+
st.write("Generated Image:")
|
| 39 |
+
st.image(image, use_column_width=True)
|
|
|
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
+
main()
|