Spaces:
Sleeping
Sleeping
File size: 2,098 Bytes
0759822 90cb4f4 bfa9b50 90cb4f4 0759822 bfa9b50 0759822 90cb4f4 82a36a6 90cb4f4 0759822 90cb4f4 0759822 bfa9b50 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
from db.schema import Feedback
from db.crud import save_feedback, read
import streamlit as st
from datetime import datetime
import os
from dotenv import load_dotenv
load_dotenv()
VALIDATION_CODE = os.getenv("VALIDATION_CODE")
def submit_feedback(current_index):
"""Handles feedback submission to the database."""
feedback = Feedback(
id=current_index + 1,
user_id=st.session_state.username,
time_stamp=datetime.now().isoformat(),
responses=st.session_state.responses,
)
try:
save_feedback(feedback)
st.session_state.completed = True
st.rerun()
except Exception as e:
st.error(f"An error occurred while submitting feedback: {e}")
def any_value_zero(response):
return any(
any(value == 0 for value in query.values())
for query in [response.query_v, response.query_p0, response.query_p1]
)
def navigation_buttons(data, ratings_v, ratings_p0, ratings_p1):
"""Display navigation buttons."""
current_index = st.session_state.current_index
col1, col2, col3 = st.columns([1, 1, 2])
with col1: # Back button #TODO fix
if st.button("Back") and current_index > 0:
st.session_state.current_index -= 1
st.rerun()
with col2: # Next button
if st.button("Next"):
if any(rating == 0 for rating in [ratings_v, ratings_p0, ratings_p1]):
st.warning("Please provide a rating before proceeding.")
else:
if current_index < len(data) - 1:
st.session_state.current_index += 1
st.rerun()
else:
submit_feedback(current_index)
with col3: # Save & Resume Later button
if st.button("Exit & Resume Later"):
last_response = st.session_state.responses[-1]
if not any_value_zero(last_response):
submit_feedback(current_index)
else:
st.session_state.completed = True
st.rerun()
# submit_feedback(current_index)
|