meraj12 commited on
Commit
b698950
·
verified ·
1 Parent(s): de36742

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -14
app.py CHANGED
@@ -1,23 +1,24 @@
1
- # app.py
2
  import streamlit as st
3
  import torch
4
  import io
5
- from PIL import Image
6
  from diffusers import StableDiffusionPipeline
 
 
 
 
 
7
 
8
- # Configuration
9
  MODEL_ID = "CompVis/stable-diffusion-v1-4"
10
- DEFAULT_STEPS = 25
11
- DEFAULT_GUIDANCE = 7.5
12
 
13
  @st.cache_resource(show_spinner=False)
14
  def load_model():
15
  pipe = StableDiffusionPipeline.from_pretrained(
16
  MODEL_ID,
17
  torch_dtype=torch.float32,
18
- use_safetensors=False, # Force .bin files for compatibility
19
- safety_checker=None,
20
- requires_safety_checker=False
21
  )
22
  pipe = pipe.to("cpu")
23
  pipe.enable_attention_slicing()
@@ -27,7 +28,7 @@ def main():
27
  st.set_page_config(page_title="Poetry to Image", page_icon="🎨")
28
  st.title("✨ Romantic Text to Image Converter")
29
 
30
- # Session state initialization
31
  if 'generated_image' not in st.session_state:
32
  st.session_state.generated_image = None
33
  if 'error' not in st.session_state:
@@ -36,14 +37,14 @@ def main():
36
  # Sidebar controls
37
  with st.sidebar:
38
  st.header("Settings")
39
- num_steps = st.slider("Inference Steps", 10, 50, DEFAULT_STEPS)
40
- guidance_scale = st.slider("Guidance Scale", 3.0, 15.0, DEFAULT_GUIDANCE)
41
 
42
  # Main interface
43
  prompt = st.text_area(
44
  "Enter your romantic text:",
45
  height=150,
46
- placeholder="Example: 'Your eyes sparkle like stars...'"
47
  )
48
 
49
  if st.button("Generate Image", type="primary"):
@@ -51,10 +52,10 @@ def main():
51
  st.session_state.error = None
52
 
53
  if not prompt.strip():
54
- st.session_state.error = "Please enter some text!"
55
  else:
56
  try:
57
- with st.spinner("Creating artwork (3-8 minutes)..."):
58
  pipe = load_model()
59
  image = pipe(
60
  prompt,
 
 
1
  import streamlit as st
2
  import torch
3
  import io
 
4
  from diffusers import StableDiffusionPipeline
5
+ from PIL import Image
6
+
7
+ # Disable unnecessary warnings
8
+ import warnings
9
+ warnings.filterwarnings("ignore")
10
 
11
+ # Model configuration
12
  MODEL_ID = "CompVis/stable-diffusion-v1-4"
 
 
13
 
14
  @st.cache_resource(show_spinner=False)
15
  def load_model():
16
  pipe = StableDiffusionPipeline.from_pretrained(
17
  MODEL_ID,
18
  torch_dtype=torch.float32,
19
+ use_safetensors=False, # Force using .bin files
20
+ use_auth_token=False,
21
+ safety_checker=None
22
  )
23
  pipe = pipe.to("cpu")
24
  pipe.enable_attention_slicing()
 
28
  st.set_page_config(page_title="Poetry to Image", page_icon="🎨")
29
  st.title("✨ Romantic Text to Image Converter")
30
 
31
+ # Initialize session state
32
  if 'generated_image' not in st.session_state:
33
  st.session_state.generated_image = None
34
  if 'error' not in st.session_state:
 
37
  # Sidebar controls
38
  with st.sidebar:
39
  st.header("Settings")
40
+ num_steps = st.slider("Inference Steps", 10, 50, 25)
41
+ guidance_scale = st.slider("Guidance Scale", 3.0, 15.0, 7.5)
42
 
43
  # Main interface
44
  prompt = st.text_area(
45
  "Enter your romantic text:",
46
  height=150,
47
+ placeholder="Example: 'Your smile shines brighter than the sun...'"
48
  )
49
 
50
  if st.button("Generate Image", type="primary"):
 
52
  st.session_state.error = None
53
 
54
  if not prompt.strip():
55
+ st.session_state.error = "Please enter some text first!"
56
  else:
57
  try:
58
+ with st.spinner("Creating artwork (5-10 minutes)..."):
59
  pipe = load_model()
60
  image = pipe(
61
  prompt,