Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,21 @@
|
|
| 1 |
-
import os
|
| 2 |
-
|
| 3 |
-
# Install missing dependencies
|
| 4 |
-
try:
|
| 5 |
-
import torch
|
| 6 |
-
import torchvision
|
| 7 |
-
import diffusers
|
| 8 |
-
import transformers
|
| 9 |
-
from PIL import Image
|
| 10 |
-
except ModuleNotFoundError as e:
|
| 11 |
-
missing_module = str(e).split("'")[1]
|
| 12 |
-
os.system(f"pip install {missing_module}")
|
| 13 |
-
|
| 14 |
-
import torch
|
| 15 |
import streamlit as st
|
| 16 |
-
from diffusers import
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
# Streamlit UI
|
| 20 |
-
st.title("Lightweight Text-to-Image Generator (CPU Friendly)")
|
| 21 |
-
st.write("Enter a description, and an AI model will generate an image!")
|
| 22 |
|
| 23 |
# Load the model
|
| 24 |
-
@st.cache_resource
|
| 25 |
def load_model():
|
| 26 |
-
model_id = "CompVis/
|
| 27 |
-
pipe =
|
| 28 |
-
pipe.to("cpu") # Ensure the model runs on CPU
|
| 29 |
return pipe
|
| 30 |
|
| 31 |
pipe = load_model()
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# User input
|
| 34 |
text_input = st.text_input("Enter your description:")
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Load the model
|
| 6 |
+
@st.cache_resource
|
| 7 |
def load_model():
|
| 8 |
+
model_id = "CompVis/stable-diffusion-v1-4"
|
| 9 |
+
pipe = StableDiffusionPipeline.from_pretrained(model_id)
|
| 10 |
+
pipe = pipe.to("cpu") # Ensure the model runs on CPU
|
| 11 |
return pipe
|
| 12 |
|
| 13 |
pipe = load_model()
|
| 14 |
|
| 15 |
+
# Streamlit UI
|
| 16 |
+
st.title("Text-to-Image Generator")
|
| 17 |
+
st.write("Enter a description, and the AI model will generate an image!")
|
| 18 |
+
|
| 19 |
# User input
|
| 20 |
text_input = st.text_input("Enter your description:")
|
| 21 |
|