Zekun Wu
commited on
Commit
•
0bf6595
1
Parent(s):
f2aee45
update
Browse files
app.py
CHANGED
@@ -1,27 +1,41 @@
|
|
1 |
import streamlit as st
|
2 |
from evaluator import evaluator
|
|
|
3 |
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
-
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
# st.write('### Question')
|
15 |
-
# st.write(question)
|
16 |
-
# st.write('### Explanation')
|
17 |
-
# st.write(explaination)
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
1 |
import streamlit as st
|
2 |
from evaluator import evaluator
|
3 |
+
import os
|
4 |
|
5 |
+
# Function to check password
|
6 |
+
def check_password():
|
7 |
+
def password_entered():
|
8 |
+
if password_input == os.getenv('PASSWORD'):
|
9 |
+
st.session_state['password_correct'] = True
|
10 |
+
else:
|
11 |
+
st.error("Incorrect Password, please try again.")
|
12 |
+
|
13 |
+
# Create a password input field and a button for submission
|
14 |
+
password_input = st.text_input("Enter Password:", type="password")
|
15 |
+
submit_button = st.button("Submit", on_click=password_entered)
|
16 |
|
17 |
+
# If the button is pressed and password is not correct, display an error
|
18 |
+
if submit_button and not st.session_state.get('password_correct', False):
|
19 |
+
st.error("Please enter a valid password to access the demo.")
|
20 |
|
21 |
+
# Title of the application
|
22 |
+
st.title('Natural Language Explanation Demo')
|
23 |
|
24 |
+
# Check if password has been validated, if not, call the check_password function
|
25 |
+
if not st.session_state.get('password_correct', False):
|
26 |
+
check_password()
|
27 |
+
else:
|
28 |
+
model_name = st.selectbox('Select a model:', ['gpt4-1106', 'gpt35-1106'])
|
29 |
|
30 |
+
question = st.text_input('Enter question:', '')
|
31 |
+
explanation = st.text_input('Enter explanation:', '')
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
if st.button('Evaluate Explanation'):
|
34 |
+
if question and explanation:
|
35 |
+
eval = evaluator(model_name)
|
36 |
+
scores = eval(question, explanation)
|
37 |
+
st.write('### Scores')
|
38 |
+
for principle, score in scores.items():
|
39 |
+
st.write(f"{principle}: {score}")
|
40 |
+
else:
|
41 |
+
st.error('Please enter both a question and an explanation to evaluate.')
|