Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,25 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from
|
| 3 |
import torch
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
@st.
|
| 7 |
def load_model():
|
| 8 |
model_id = "CompVis/stable-diffusion-v1-4"
|
| 9 |
-
|
| 10 |
-
pipe.
|
|
|
|
| 11 |
return pipe
|
| 12 |
|
| 13 |
-
# Load the model
|
| 14 |
pipe = load_model()
|
| 15 |
|
| 16 |
-
# Streamlit
|
| 17 |
-
st.title("Text
|
| 18 |
-
st.
|
| 19 |
-
|
| 20 |
-
# User input
|
| 21 |
-
text_input = st.text_input("Enter your description:")
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
image = pipe(text_input).images[0] # Generate image
|
| 28 |
-
st.image(image, caption="Generated Image", use_column_width=True)
|
| 29 |
-
except Exception as e:
|
| 30 |
-
st.error(f"Error generating image: {e}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from transformers import CLIPTextModel, CLIPTokenizer
|
| 3 |
import torch
|
| 4 |
+
from torch import autocast
|
| 5 |
+
from diffusers import StableDiffusionPipeline
|
| 6 |
|
| 7 |
+
# Load the model
|
| 8 |
+
@st.cache(allow_output_mutation=True)
|
| 9 |
def load_model():
|
| 10 |
model_id = "CompVis/stable-diffusion-v1-4"
|
| 11 |
+
device = "cpu"
|
| 12 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
|
| 13 |
+
pipe.to(device)
|
| 14 |
return pipe
|
| 15 |
|
|
|
|
| 16 |
pipe = load_model()
|
| 17 |
|
| 18 |
+
# Streamlit app
|
| 19 |
+
st.title("Text to Image Generator")
|
| 20 |
+
prompt = st.text_input("Enter your prompt:", "A scenic landscape of mountains during sunset")
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
if st.button("Generate Image"):
|
| 23 |
+
with st.spinner("Generating..."):
|
| 24 |
+
image = pipe(prompt)["sample"][0]
|
| 25 |
+
st.image(image, caption=prompt)
|
|
|
|
|
|
|
|
|
|
|
|