Spaces:
Sleeping
Sleeping
Dua Rajper commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,25 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
from transformers import pipeline
|
| 3 |
-
from diffusers import StableDiffusionPipeline
|
| 4 |
import torch
|
|
|
|
| 5 |
|
| 6 |
-
# Load the pre-trained Stable Diffusion model
|
| 7 |
@st.cache_resource
|
| 8 |
def load_model():
|
| 9 |
-
|
| 10 |
-
model = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v-1-4-original")
|
| 11 |
-
model.to("cpu") # Ensure it uses CPU for inference
|
| 12 |
-
return model
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
prompt = st.text_input("Enter
|
| 21 |
|
| 22 |
if prompt:
|
| 23 |
st.write("Generating image... Please wait.")
|
| 24 |
-
|
| 25 |
-
# Load model once (from the Hugging Face model hub)
|
| 26 |
model = load_model()
|
| 27 |
-
|
| 28 |
-
# Generate the image from the text prompt
|
| 29 |
with torch.no_grad():
|
| 30 |
image = model(prompt).images[0]
|
| 31 |
-
|
| 32 |
-
# Show the generated image in the app
|
| 33 |
st.image(image, caption="Generated Image", use_column_width=True)
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
| 2 |
import torch
|
| 3 |
+
from diffusers import StableDiffusionPipeline
|
| 4 |
|
|
|
|
| 5 |
@st.cache_resource
|
| 6 |
def load_model():
|
| 7 |
+
model_id = "CompVis/stable-diffusion-v1-4" # Correct model ID
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 10 |
+
model_id,
|
| 11 |
+
torch_dtype=torch.float32 # Ensure CPU compatibility
|
| 12 |
+
)
|
| 13 |
|
| 14 |
+
pipe.to("cpu") # Force CPU execution
|
| 15 |
+
return pipe
|
| 16 |
|
| 17 |
+
st.title("Text-to-Image Generator")
|
| 18 |
+
prompt = st.text_input("Enter a prompt:")
|
| 19 |
|
| 20 |
if prompt:
|
| 21 |
st.write("Generating image... Please wait.")
|
|
|
|
|
|
|
| 22 |
model = load_model()
|
|
|
|
|
|
|
| 23 |
with torch.no_grad():
|
| 24 |
image = model(prompt).images[0]
|
|
|
|
|
|
|
| 25 |
st.image(image, caption="Generated Image", use_column_width=True)
|