File size: 7,138 Bytes
17d7268 853f9ad 17d7268 853f9ad 17d7268 3672495 17d7268 |
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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
import streamlit as st
import os
import random
import importlib.util
import firebase_admin
from firebase_admin import credentials, firestore
import json
# Set page configuration as the first command
st.set_page_config(
page_title="TB Chatbot Evaluation",
page_icon="👋",
)
PASSCODE = os.environ["MY_PASSCODE"]
creds_dict = {
"type": os.environ.get("FIREBASE_TYPE", "service_account"),
"project_id": os.environ.get("FIREBASE_PROJECT_ID"),
"private_key_id": os.environ.get("FIREBASE_PRIVATE_KEY_ID"),
"private_key": os.environ.get("FIREBASE_PRIVATE_KEY", "").replace("\\n", "\n"),
"client_email": os.environ.get("FIREBASE_CLIENT_EMAIL"),
"client_id": os.environ.get("FIREBASE_CLIENT_ID"),
"auth_uri": os.environ.get("FIREBASE_AUTH_URI", "https://accounts.google.com/o/oauth2/auth"),
"token_uri": os.environ.get("FIREBASE_TOKEN_URI", "https://oauth2.googleapis.com/token"),
"auth_provider_x509_cert_url": os.environ.get("FIREBASE_AUTH_PROVIDER_X509_CERT_URL",
"https://www.googleapis.com/oauth2/v1/certs"),
"client_x509_cert_url": os.environ.get("FIREBASE_CLIENT_X509_CERT_URL"),
"universe_domain": "googleapis.com"
}
# Create a temporary JSON file
file_path = "coco-evaluation-firebase-adminsdk-p3m64-99c4ea22c1.json"
with open(file_path, 'w') as json_file:
json.dump(creds_dict, json_file, indent=2)
# Initialize Firebase
if not firebase_admin._apps:
cred = credentials.Certificate("coco-evaluation-firebase-adminsdk-p3m64-99c4ea22c1.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
# Set passcode for authentication
PASSCODE = os.environ["MY_PASSCODE"]
# Initialize authentication state
if "authenticated" not in st.session_state:
st.session_state["authenticated"] = False
# Initialize session state variables
def init_session_state():
if "authenticated" not in st.session_state:
st.session_state["authenticated"] = False
if "evaluator_confirmed" not in st.session_state:
st.session_state["evaluator_confirmed"] = None
if "model_order" not in st.session_state:
st.session_state["model_order"] = []
if "current_index" not in st.session_state:
st.session_state["current_index"] = 0
if "models_completed" not in st.session_state:
st.session_state["models_completed"] = False
if "evaluation_status" not in st.session_state or not st.session_state["evaluation_status"]:
st.session_state["evaluation_status"] = {}
if "all_evaluations" not in st.session_state:
st.session_state["all_evaluations"] = {}
if "evaluation_ids" not in st.session_state:
st.session_state["evaluation_ids"] = {}
if "start_time" not in st.session_state:
st.session_state["start_time"] = None
if "evaluation_durations" not in st.session_state:
st.session_state["evaluation_durations"] = {}
if "submitted_evaluations" not in st.session_state:
st.session_state["submitted_evaluations"] = set()
init_session_state()
# Display Welcome Page
if not st.session_state["authenticated"]:
st.markdown(f"<h1 style='text-align: center;'>Welcome to the TB Chatbot Evaluation</h1>", unsafe_allow_html=True)
col1, col2, col3 = st.columns([2, 1, 1])
with col1:
st.write("Are you an evaluator?")
with col2:
if st.button("Yes"):
st.session_state["evaluator_confirmed"] = True
with col3:
if st.button("No"):
st.session_state["evaluator_confirmed"] = False
if st.session_state["evaluator_confirmed"]:
evaluator_id = st.text_input("Enter your Evaluator ID (can be anything)")
passcode = st.text_input("Enter Passcode to Access Models (password is the same)", type="password")
if st.button("Submit"):
print("Hello")
if passcode == PASSCODE and evaluator_id:
print("Submitted")
# Save Evaluator ID
db.collection("evaluator_ids").document(evaluator_id).set({
"evaluator_id": evaluator_id,
"timestamp": firestore.SERVER_TIMESTAMP
})
# Update session state
st.session_state["authenticated"] = True
st.session_state["evaluator_id"] = evaluator_id
# Show the main content only if authenticated
if st.session_state["authenticated"]:
# Sidebar with only randomized page navigation
with st.sidebar:
# Only create the page mapping if it doesn't already exist in the session state
if "page_mapping" not in st.session_state:
# Get list of page files and randomize their order
PAGES_DIR = "pages"
page_files = [f for f in os.listdir(PAGES_DIR) if f.endswith(".py")]
random.shuffle(page_files)
# Create generic names for display
generic_names = [f"Model {chr(65 + i)}" for i in range(len(page_files))]
# Create a dictionary to map display names to file paths
st.session_state["page_mapping"] = {
generic_name: os.path.join(PAGES_DIR, page_file) for generic_name, page_file in zip(generic_names, page_files)
}
# Retrieve the consistent mapping from session state
pages = st.session_state["page_mapping"]
# Sidebar navigation selectbox with generic labels
selected_generic_name = st.selectbox("Navigation", list(pages.keys()), label_visibility="collapsed")
# Load and run the selected page dynamically using the selected generic name
selected_page_path = pages[selected_generic_name]
spec = importlib.util.spec_from_file_location(selected_generic_name, selected_page_path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
# Display main welcome message
st.markdown("""
# Welcome to the TB Chatbot Simulation Portal
This portal allows you to interact with our TB-powered chatbot, built using OpenAI's GPT-4. Here, you can evaluate multiple chatbot configurations, each designed to foster trust, empathy, and medical accuracy in responses.
## Purpose
Your task is to assess the chatbot models by interacting with them using patient scenario-based questions. Evaluate each model based on the following principles:
### Trust
- Does the response convey confidence and reliability?
- Are the answers factually accurate and rooted in medical expertise?
### Medical Accuracy
- Are responses aligned with current medical guidelines and best practices?
- Do they avoid misinformation or potentially harmful suggestions?
### Empathy
- Does the chatbot demonstrate understanding and compassion?
- Are responses emotionally sensitive and supportive?
Your feedback will help us identify the best model to support our mission of enhancing patient communication and care through AI-driven solutions.
""")
|