awacke1 commited on
Commit
638fb8d
Β·
verified Β·
1 Parent(s): 17aa09a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -409,6 +409,11 @@ def create_streamlit_interface():
409
  col1, col2, col3, col4 = st.columns([3, 1, 1, 2])
410
  with col1:
411
  st.markdown(line)
 
 
 
 
 
412
  with col2:
413
  vote_count = chat_votes.get(line.split('. ')[1] if '. ' in line else line, 0)
414
  if st.button(f"πŸ‘ {vote_count}", key=f"chat_vote_{i}"):
@@ -446,6 +451,7 @@ def create_streamlit_interface():
446
  filename = await save_pasted_image(st.session_state.pasted_image_data, st.session_state.username)
447
  if filename:
448
  markdown_response += f"\n- **Image**: ![Pasted Image]({filename})"
 
449
  st.session_state.pasted_image_data = None
450
  await save_chat_entry(st.session_state.username, markdown_response)
451
  del st.session_state.quote_line
@@ -464,14 +470,15 @@ def create_streamlit_interface():
464
  if st.button("Send πŸš€", key="send_button") and message.strip():
465
  loop.run_until_complete(save_chat_entry(st.session_state.username, message))
466
  if st.session_state.pasted_image_data:
467
- filename = loop.run_until_complete(save_pasted_image(st.session_state.pasted_image_data, st.session_state.username))
468
  if filename:
469
  loop.run_until_complete(save_chat_entry(st.session_state.username, f"Pasted image: {filename}"))
470
  st.session_state.pasted_image_data = None
471
  st.session_state.message_text = ''
472
  st.rerun()
473
 
474
- components.html(
 
475
  """
476
  <div id="paste-target">Paste an image here (Ctrl+V)</div>
477
  <script>
@@ -498,6 +505,13 @@ def create_streamlit_interface():
498
  """,
499
  height=100
500
  )
 
 
 
 
 
 
 
501
 
502
  st.subheader("Media Gallery 🎨🎢πŸŽ₯")
503
  uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp3', 'mp4'])
 
409
  col1, col2, col3, col4 = st.columns([3, 1, 1, 2])
410
  with col1:
411
  st.markdown(line)
412
+ # Display image if the line contains an image reference
413
+ if "Pasted image:" in line:
414
+ image_path = line.split("Pasted image: ")[1].strip()
415
+ if os.path.exists(image_path):
416
+ st.image(image_path, use_container_width=True)
417
  with col2:
418
  vote_count = chat_votes.get(line.split('. ')[1] if '. ' in line else line, 0)
419
  if st.button(f"πŸ‘ {vote_count}", key=f"chat_vote_{i}"):
 
451
  filename = await save_pasted_image(st.session_state.pasted_image_data, st.session_state.username)
452
  if filename:
453
  markdown_response += f"\n- **Image**: ![Pasted Image]({filename})"
454
+ await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
455
  st.session_state.pasted_image_data = None
456
  await save_chat_entry(st.session_state.username, markdown_response)
457
  del st.session_state.quote_line
 
470
  if st.button("Send πŸš€", key="send_button") and message.strip():
471
  loop.run_until_complete(save_chat_entry(st.session_state.username, message))
472
  if st.session_state.pasted_image_data:
473
+ filename = await save_pasted_image(st.session_state.pasted_image_data, st.session_state.username)
474
  if filename:
475
  loop.run_until_complete(save_chat_entry(st.session_state.username, f"Pasted image: {filename}"))
476
  st.session_state.pasted_image_data = None
477
  st.session_state.message_text = ''
478
  st.rerun()
479
 
480
+ # Image paste component
481
+ pasted_image = components.html(
482
  """
483
  <div id="paste-target">Paste an image here (Ctrl+V)</div>
484
  <script>
 
505
  """,
506
  height=100
507
  )
508
+ if pasted_image and st.session_state.pasted_image_data != pasted_image:
509
+ st.session_state.pasted_image_data = pasted_image
510
+ filename = await save_pasted_image(st.session_state.pasted_image_data, st.session_state.username)
511
+ if filename:
512
+ await save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
513
+ st.session_state.pasted_image_data = None
514
+ st.rerun()
515
 
516
  st.subheader("Media Gallery 🎨🎢πŸŽ₯")
517
  uploaded_file = st.file_uploader("Upload Media", type=['png', 'jpg', 'mp3', 'mp4'])