Zekun Wu commited on
Commit
a1320fa
1 Parent(s): 0bf6595
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -2,6 +2,19 @@ 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():
@@ -10,32 +23,35 @@ def check_password():
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.')
 
2
  from evaluator import evaluator
3
  import os
4
 
5
+ # Predefined examples
6
+ examples = {
7
+ 'good': {
8
+ 'question': "What causes rainbows to appear in the sky?",
9
+ '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."
10
+ },
11
+ 'bad': {
12
+ 'question': "What causes rainbows to appear in the sky?",
13
+ '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."
14
+ }
15
+ }
16
+
17
+
18
  # Function to check password
19
  def check_password():
20
  def password_entered():
 
23
  else:
24
  st.error("Incorrect Password, please try again.")
25
 
 
26
  password_input = st.text_input("Enter Password:", type="password")
27
  submit_button = st.button("Submit", on_click=password_entered)
28
 
 
29
  if submit_button and not st.session_state.get('password_correct', False):
30
  st.error("Please enter a valid password to access the demo.")
31
 
32
+
33
  # Title of the application
34
  st.title('Natural Language Explanation Demo')
35
 
36
+ # Check if password has been validated
37
  if not st.session_state.get('password_correct', False):
38
  check_password()
39
  else:
40
  model_name = st.selectbox('Select a model:', ['gpt4-1106', 'gpt35-1106'])
41
 
42
+ # Option to select an example type
43
+ example_type = st.radio("Choose an example type:", ('good', 'bad'))
44
+ example = examples[example_type]
45
+
46
+ st.write('### Example Question')
47
+ st.write(example['question'])
48
+
49
+ st.write('### Example Explanation')
50
+ st.write(example['explanation'])
51
 
52
  if st.button('Evaluate Explanation'):
53
+ eval = evaluator(model_name)
54
+ scores = eval(example['question'], example['explanation'])
55
+ st.write('### Scores')
56
+ for principle, score in scores.items():
57
+ st.write(f"{principle}: {score}")