artintel235 commited on
Commit
b9d5493
·
verified ·
1 Parent(s): 9fc847d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -18
app.py CHANGED
@@ -285,8 +285,6 @@ def login_form():
285
  login_identifier = st.text_input("Email or Username", key="login_identifier")
286
  password = st.text_input("Password", type="password", key="login_password")
287
  submit_button = st.form_submit_button("Login", on_click=login_callback)
288
-
289
- # Main app screen (after login)
290
  def main_app():
291
  st.subheader(f"Welcome, {st.session_state.display_name}!")
292
  st.write("Enter a prompt below to generate an image.")
@@ -325,33 +323,102 @@ def main_app():
325
  st.warning("Please enter a prompt to generate an image.")
326
 
327
  st.header("Your Generated Images")
328
- # Load initial batch of images
329
- if st.session_state.images_data == []:
 
330
  st.session_state.images_data = load_image_data(st.session_state.current_user, st.session_state.start_index, st.session_state.batch_size)
 
331
 
 
332
  if st.session_state.images_data:
333
- for image_data in st.session_state.images_data:
334
- col1, col2 = st.columns([1,2])
335
- with col1:
336
- st.image(image_data['image_url'], width = 150)
337
- with col2:
338
- st.write(f"**Prompt:** {image_data['prompt']}")
339
- st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
340
- st.write(f"**Realism:** {image_data['realism']}")
341
- st.markdown("---")
 
 
342
 
343
  # Load more button
344
  if st.button("Load More Images"):
345
  st.session_state.start_index += st.session_state.batch_size
346
- new_images = load_image_data(st.session_state.current_user, st.session_state.start_index, st.session_state.batch_size)
347
- if new_images:
348
- st.session_state.images_data.extend(new_images)
349
- else:
350
- st.write("No more images available")
351
 
352
  # Logout button
353
  if st.button("Logout", on_click=logout_callback):
354
  pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
 
356
  # Render the appropriate screen based on login status
357
  if st.session_state.logged_in:
 
285
  login_identifier = st.text_input("Email or Username", key="login_identifier")
286
  password = st.text_input("Password", type="password", key="login_password")
287
  submit_button = st.form_submit_button("Login", on_click=login_callback)
 
 
288
  def main_app():
289
  st.subheader(f"Welcome, {st.session_state.display_name}!")
290
  st.write("Enter a prompt below to generate an image.")
 
323
  st.warning("Please enter a prompt to generate an image.")
324
 
325
  st.header("Your Generated Images")
326
+
327
+ # Load initial batch of images (or reset if needed)
328
+ if st.session_state.images_data == [] or st.session_state.load_more_pressed == True:
329
  st.session_state.images_data = load_image_data(st.session_state.current_user, st.session_state.start_index, st.session_state.batch_size)
330
+ st.session_state.load_more_pressed = False
331
 
332
+ # Setup columns for horizontal slider layout
333
  if st.session_state.images_data:
334
+ num_images = len(st.session_state.images_data)
335
+ cols = st.columns(num_images) # dynamically create columns according to data
336
+ for i, image_data in enumerate(st.session_state.images_data):
337
+ with cols[i]:
338
+ st.image(image_data['image_url'], width = 150)
339
+ st.write(f"**Prompt:** {image_data['prompt']}")
340
+ st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
341
+ st.write(f"**Realism:** {image_data['realism']}")
342
+ st.markdown("---")
343
+ else:
344
+ st.write("No image generated yet!")
345
 
346
  # Load more button
347
  if st.button("Load More Images"):
348
  st.session_state.start_index += st.session_state.batch_size
349
+ st.session_state.load_more_pressed = True
350
+ # No more loading logic here as we are now loading all the images together using `st.session_state.load_more_pressed` flag
351
+
 
 
352
 
353
  # Logout button
354
  if st.button("Logout", on_click=logout_callback):
355
  pass
356
+ # Main app screen (after login)
357
+ # def main_app():
358
+ # st.subheader(f"Welcome, {st.session_state.display_name}!")
359
+ # st.write("Enter a prompt below to generate an image.")
360
+
361
+ # # Input fields
362
+ # prompt = st.text_input("Prompt", key="image_prompt", placeholder="Describe the image you want to generate")
363
+ # aspect_ratio = st.radio(
364
+ # "Aspect Ratio",
365
+ # options=["1:1", "3:4", "4:3", "9:16", "16:9", "9:21", "21:9"],
366
+ # index=5
367
+ # )
368
+ # realism = st.checkbox("Realism", value=False)
369
+
370
+ # if st.button("Generate Image"):
371
+ # if prompt:
372
+ # with st.spinner("Generating Image..."):
373
+ # image_result = generate_image(prompt, aspect_ratio, realism)
374
+ # if isinstance(image_result, tuple) and len(image_result) == 2 and image_result[0] is not None:
375
+ # image, image_url = image_result
376
+ # st.image(image, caption="Generated Image", use_column_width=True)
377
+
378
+ # # Upload image to cloud storage and store url
379
+ # cloud_storage_url = upload_image_to_storage(image, st.session_state.current_user)
380
+
381
+ # if cloud_storage_url:
382
+ # # Store image data in database
383
+ # store_image_data_in_db(st.session_state.current_user, prompt, aspect_ratio, realism, cloud_storage_url)
384
+ # st.success("Image stored to database successfully!")
385
+
386
+ # download_path = download_image(image_url)
387
+ # if download_path:
388
+ # st.download_button(label="Download Image", data = open(download_path, "rb"), file_name = f"image.png")
389
+ # else:
390
+ # st.error(f"Image generation failed: {image_result}")
391
+ # else:
392
+ # st.warning("Please enter a prompt to generate an image.")
393
+
394
+ # st.header("Your Generated Images")
395
+ # # Load initial batch of images
396
+ # if st.session_state.images_data == []:
397
+ # st.session_state.images_data = load_image_data(st.session_state.current_user, st.session_state.start_index, st.session_state.batch_size)
398
+
399
+ # if st.session_state.images_data:
400
+ # for image_data in st.session_state.images_data:
401
+ # col1, col2 = st.columns([1,2])
402
+ # with col1:
403
+ # st.image(image_data['image_url'], width = 150)
404
+ # with col2:
405
+ # st.write(f"**Prompt:** {image_data['prompt']}")
406
+ # st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
407
+ # st.write(f"**Realism:** {image_data['realism']}")
408
+ # st.markdown("---")
409
+
410
+ # # Load more button
411
+ # if st.button("Load More Images"):
412
+ # st.session_state.start_index += st.session_state.batch_size
413
+ # new_images = load_image_data(st.session_state.current_user, st.session_state.start_index, st.session_state.batch_size)
414
+ # if new_images:
415
+ # st.session_state.images_data.extend(new_images)
416
+ # else:
417
+ # st.write("No more images available")
418
+
419
+ # # Logout button
420
+ # if st.button("Logout", on_click=logout_callback):
421
+ # pass
422
 
423
  # Render the appropriate screen based on login status
424
  if st.session_state.logged_in: