Dua Rajper commited on
Commit
2450108
·
verified ·
1 Parent(s): 58bc10e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -18
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
- # You can load any Stable Diffusion model here
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
- # Initialize Streamlit components
15
- st.title("Text-to-Image Generator")
 
 
16
 
17
- st.write("Enter a description and generate an image!")
 
18
 
19
- # User input for text prompt
20
- prompt = st.text_input("Enter your text prompt here:")
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)