Spaces:
Runtime error
Runtime error
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,37 +1,37 @@
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
import streamlit as st
|
| 4 |
-
import torch
|
| 5 |
-
from transformers import CLIPTextModel, CLIPFeatureExtractor
|
| 6 |
-
import numpy as np
|
| 7 |
-
import matplotlib.pyplot as plt
|
| 8 |
|
| 9 |
-
# Load the
|
| 10 |
@st.cache(allow_output_mutation=True)
|
| 11 |
-
def
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
return pipe
|
| 16 |
|
| 17 |
-
# Main function
|
| 18 |
def main():
|
| 19 |
-
st.title("Stable Diffusion
|
| 20 |
-
st.
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
if st.button("Generate"):
|
| 27 |
if not prompt:
|
| 28 |
-
st.
|
| 29 |
return
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
image =
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
main()
|
|
|
|
| 1 |
from diffusers import StableDiffusionPipeline
|
| 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("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
|
| 10 |
+
pipeline = pipeline.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 11 |
+
return pipeline
|
|
|
|
| 12 |
|
|
|
|
| 13 |
def main():
|
| 14 |
+
st.title("Stable Diffusion Image Generator")
|
| 15 |
+
st.write("Generate images from text prompts using Stable Diffusion 2.1")
|
| 16 |
+
|
| 17 |
+
# Initialize the pipeline
|
| 18 |
+
pipeline = load_pipeline()
|
| 19 |
+
|
| 20 |
+
# Text input for the prompt
|
| 21 |
+
prompt = st.text_input("Enter your text prompt", "")
|
| 22 |
+
|
| 23 |
+
# Generate button
|
| 24 |
if st.button("Generate"):
|
| 25 |
if not prompt:
|
| 26 |
+
st.warning("Please enter a prompt first.")
|
| 27 |
return
|
| 28 |
+
|
| 29 |
+
st.write("Generating your image...")
|
| 30 |
+
with torch.no_grad():
|
| 31 |
+
image = pipeline(prompt).images[0]
|
| 32 |
+
|
| 33 |
+
st.write("Generated Image:")
|
| 34 |
+
st.image(image, use_column_width=True)
|
| 35 |
|
| 36 |
if __name__ == "__main__":
|
| 37 |
main()
|