File size: 1,592 Bytes
0a026c0
 
0bf6595
0a026c0
0bf6595
 
 
 
 
 
 
 
 
 
 
0a026c0
0bf6595
 
 
0a026c0
0bf6595
 
0a026c0
0bf6595
 
 
 
 
0a026c0
0bf6595
 
0a026c0
0bf6595
 
 
 
 
 
 
 
 
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
import streamlit as st
from evaluator import evaluator
import os

# 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.")

    # Create a password input field and a button for submission
    password_input = st.text_input("Enter Password:", type="password")
    submit_button = st.button("Submit", on_click=password_entered)

    # If the button is pressed and password is not correct, display an error
    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, call the check_password function
if not st.session_state.get('password_correct', False):
    check_password()
else:
    model_name = st.selectbox('Select a model:', ['gpt4-1106', 'gpt35-1106'])

    question = st.text_input('Enter question:', '')
    explanation = st.text_input('Enter explanation:', '')

    if st.button('Evaluate Explanation'):
        if question and explanation:
            eval = evaluator(model_name)
            scores = eval(question, explanation)
            st.write('### Scores')
            for principle, score in scores.items():
                st.write(f"{principle}: {score}")
        else:
            st.error('Please enter both a question and an explanation to evaluate.')