Zekun Wu
update
a1320fa
raw
history blame
2.02 kB
import streamlit as st
from evaluator import evaluator
import os
# Predefined examples
examples = {
'good': {
'question': "What causes rainbows to appear in the sky?",
'explanation': "Rainbows appear when sunlight is refracted, dispersed, and reflected inside water droplets in the atmosphere, resulting in a spectrum of light appearing in the sky."
},
'bad': {
'question': "What causes rainbows to appear in the sky?",
'explanation': "Rainbows happen because light in the sky gets mixed up and sometimes shows colors when it's raining or when there is water around."
}
}
# Function to check password
def check_password():
def password_entered():
if password_input == os.getenv('PASSWORD'):
st.session_state['password_correct'] = True
else:
st.error("Incorrect Password, please try again.")
password_input = st.text_input("Enter Password:", type="password")
submit_button = st.button("Submit", on_click=password_entered)
if submit_button and not st.session_state.get('password_correct', False):
st.error("Please enter a valid password to access the demo.")
# Title of the application
st.title('Natural Language Explanation Demo')
# Check if password has been validated
if not st.session_state.get('password_correct', False):
check_password()
else:
model_name = st.selectbox('Select a model:', ['gpt4-1106', 'gpt35-1106'])
# Option to select an example type
example_type = st.radio("Choose an example type:", ('good', 'bad'))
example = examples[example_type]
st.write('### Example Question')
st.write(example['question'])
st.write('### Example Explanation')
st.write(example['explanation'])
if st.button('Evaluate Explanation'):
eval = evaluator(model_name)
scores = eval(example['question'], example['explanation'])
st.write('### Scores')
for principle, score in scores.items():
st.write(f"{principle}: {score}")