Skip to content

Commit

Permalink
Handle better activate and deactivate camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Odrec committed Jun 11, 2024
1 parent ab5cffa commit d940af8
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/chat_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ def _activate_camera_callback():
"""
if not session_state['activate_camera']:
session_state['activate_camera'] = True
session_state['toggle_camera_label'] = "Deactivate camera"
else:
session_state['activate_camera'] = False
session_state['photo_to_use'] = []
session_state['toggle_camera_label'] = "Activate camera"
#session_state['photo_to_use'] = []

@staticmethod
def _fetch_chatbot_description():
Expand Down Expand Up @@ -390,6 +388,7 @@ def _display_camera():
"""
col3, col4, col5 = st.columns([1, 1, 1])
with col4:
float_parent(f"bottom: 20rem; background-color: var(--default-backgroundColor); padding-top: 1rem;")
st.camera_input(
session_state['_']("Take a photo"),
key='your_photo',
Expand All @@ -398,13 +397,13 @@ def _display_camera():
st.button("Use photo",
key='use_photo_button',
use_container_width=True,)
float_parent(f"bottom: 20rem; background-color: var(--default-backgroundColor); padding-top: 1rem;")
if session_state['your_photo']:
if session_state['use_photo_button']:
session_state['photo_to_use'] = session_state['your_photo']
session_state['activate_camera'] = False
session_state['toggle_camera_label'] = "Activate camera"
st.rerun()

if session_state['your_photo']:
if session_state['use_photo_button']:
session_state['photo_to_use'] = session_state['your_photo']
session_state['activate_camera'] = False
session_state['toggle_camera_label'] = "Activate camera"
st.rerun()

def _display_chat_buttons(self):
"""
Expand Down Expand Up @@ -468,10 +467,13 @@ def display_chat_interface(self):
description = self._fetch_chatbot_description()

if isinstance(description, str) and description.strip():
self._display_chat_buttons()

if session_state.get('activate_camera', False):
session_state['toggle_camera_label'] = "Deactivate camera"
self._display_camera()
else:
session_state['toggle_camera_label'] = "Activate camera"

self._display_chat_buttons()

# Initialize variables for uploaded content
uploaded_images = session_state.get('uploaded_images', [])
Expand Down

0 comments on commit d940af8

Please sign in to comment.