coztomate commited on
Commit
73cc78e
·
1 Parent(s): bd36be8

notification improved

Browse files
Files changed (1) hide show
  1. app.py +18 -14
app.py CHANGED
@@ -10,8 +10,6 @@ from openai import OpenAI
10
  import openai
11
  from diffusers import StableDiffusionPipeline
12
 
13
- # Placeholder for top-of-page notifications
14
- top_notification = st.empty()
15
 
16
  # Initialize session state variables
17
  if 'simplified_text' not in st.session_state:
@@ -77,7 +75,7 @@ def generate_caption(image_path):
77
 
78
 
79
  # Create a Streamlit app
80
- st.title("ARTSPEAK simplifier")
81
 
82
  # Display an image from the local file system
83
  logo_path = 'logo_artspeak.png' # Replace with your image path
@@ -200,9 +198,9 @@ if st.session_state['message_content_from_simplified_text']:
200
 
201
  st.markdown("---")
202
 
203
- #####
204
- ##Diffusor
205
- #####
206
  # Load Stable Diffusion model
207
  def load_diffusion_model():
208
  pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
@@ -210,40 +208,46 @@ def load_diffusion_model():
210
  return pipe
211
 
212
  # Function to generate an image and show a notification while processing
213
- def generate_image(pipe, prompt):
214
- top_notification.text('Generating image...')
215
- image = pipe(prompt).images[0]
216
- top_notification.empty() # Clear the notification after the process is done
 
217
  return image
218
 
219
- # Example with "Generate Image from New Caption" button
220
  if st.button("Generate Image from New Caption"):
 
221
  if st.session_state['new_caption']:
222
  pipe = load_diffusion_model()
223
  prompt_caption = f"contemporary art of {st.session_state['new_caption']}"
224
- st.session_state['image_from_caption'] = generate_image(pipe, prompt_caption)
225
 
226
  # Display the image generated from new caption
227
  if st.session_state['image_from_caption'] is not None:
228
  st.image(st.session_state['image_from_caption'], caption="Image from New Caption", use_column_width=True)
229
 
 
230
  # Button to generate image from simplified text
231
  if st.button("Generate Image from Simplified Text"):
 
232
  if st.session_state['simplified_text']:
233
  pipe = load_diffusion_model()
234
  prompt_summary = f"contemporary art of {st.session_state['simplified_text']}"
235
- st.session_state['image_from_simplified_text'] = generate_image(pipe, prompt_summary)
236
 
237
  # Display the image generated from simplified text
238
  if st.session_state['image_from_simplified_text'] is not None:
239
  st.image(st.session_state['image_from_simplified_text'], caption="Image from Simplified Text", use_column_width=True)
240
 
 
241
  # Button to generate image from press text
242
  if st.button("Generate Image from Press Text"):
 
243
  if st.session_state['message_content_from_simplified_text']:
244
  pipe = load_diffusion_model()
245
  prompt_press_text = f"contemporary art of {st.session_state['message_content_from_simplified_text']}"
246
- st.session_state['image_from_press_text'] = generate_image(pipe, prompt_press_text)
247
 
248
  # Display the image generated from press text
249
  if st.session_state['image_from_press_text'] is not None:
 
10
  import openai
11
  from diffusers import StableDiffusionPipeline
12
 
 
 
13
 
14
  # Initialize session state variables
15
  if 'simplified_text' not in st.session_state:
 
75
 
76
 
77
  # Create a Streamlit app
78
+ st.title("ARTSPEAK s i m p l i f i e r")
79
 
80
  # Display an image from the local file system
81
  logo_path = 'logo_artspeak.png' # Replace with your image path
 
198
 
199
  st.markdown("---")
200
 
201
+ ############
202
+ ##Diffusor##
203
+ ############
204
  # Load Stable Diffusion model
205
  def load_diffusion_model():
206
  pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
 
208
  return pipe
209
 
210
  # Function to generate an image and show a notification while processing
211
+ def generate_image(pipe, prompt, notification_placeholder):
212
+ with notification_placeholder.container():
213
+ st.text('Generating image...')
214
+ image = pipe(prompt).images[0]
215
+ st.empty() # Clear the notification after the process is done
216
  return image
217
 
218
+ # Button and notification for generating image from new caption
219
  if st.button("Generate Image from New Caption"):
220
+ notification_placeholder = st.empty()
221
  if st.session_state['new_caption']:
222
  pipe = load_diffusion_model()
223
  prompt_caption = f"contemporary art of {st.session_state['new_caption']}"
224
+ st.session_state['image_from_caption'] = generate_image(pipe, prompt_caption, notification_placeholder)
225
 
226
  # Display the image generated from new caption
227
  if st.session_state['image_from_caption'] is not None:
228
  st.image(st.session_state['image_from_caption'], caption="Image from New Caption", use_column_width=True)
229
 
230
+
231
  # Button to generate image from simplified text
232
  if st.button("Generate Image from Simplified Text"):
233
+ notification_placeholder = st.empty()
234
  if st.session_state['simplified_text']:
235
  pipe = load_diffusion_model()
236
  prompt_summary = f"contemporary art of {st.session_state['simplified_text']}"
237
+ st.session_state['image_from_simplified_text'] = generate_image(pipe, prompt_summary, notification_placeholder)
238
 
239
  # Display the image generated from simplified text
240
  if st.session_state['image_from_simplified_text'] is not None:
241
  st.image(st.session_state['image_from_simplified_text'], caption="Image from Simplified Text", use_column_width=True)
242
 
243
+
244
  # Button to generate image from press text
245
  if st.button("Generate Image from Press Text"):
246
+ notification_placeholder = st.empty()
247
  if st.session_state['message_content_from_simplified_text']:
248
  pipe = load_diffusion_model()
249
  prompt_press_text = f"contemporary art of {st.session_state['message_content_from_simplified_text']}"
250
+ st.session_state['image_from_press_text'] = generate_image(pipe, prompt_press_text, notification_placeholder)
251
 
252
  # Display the image generated from press text
253
  if st.session_state['image_from_press_text'] is not None: