Zekun Wu
commited on
Commit
•
dc6788d
1
Parent(s):
1bad9c0
update
Browse files- pages/2_batch_evaluation.py +0 -70
pages/2_batch_evaluation.py
DELETED
@@ -1,70 +0,0 @@
|
|
1 |
-
import pandas as pd
|
2 |
-
import streamlit as st
|
3 |
-
from util.evaluator import evaluator, write_evaluation_commentary
|
4 |
-
import os
|
5 |
-
|
6 |
-
# Predefined examples
|
7 |
-
examples = {
|
8 |
-
'good': {
|
9 |
-
'question': "What causes rainbows to appear in the sky?",
|
10 |
-
'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."
|
11 |
-
},
|
12 |
-
'bad': {
|
13 |
-
'question': "What causes rainbows to appear in the sky?",
|
14 |
-
'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."
|
15 |
-
}
|
16 |
-
}
|
17 |
-
|
18 |
-
# Function to check password
|
19 |
-
def check_password():
|
20 |
-
def password_entered():
|
21 |
-
if password_input == os.getenv('PASSWORD'):
|
22 |
-
st.session_state['password_correct'] = True
|
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 |
-
def batch_evaluate(uploaded_file):
|
33 |
-
df = pd.read_csv(uploaded_file)
|
34 |
-
eval = evaluator(model_name='gpt4-1106') # Assuming model name is fixed for simplicity
|
35 |
-
results = []
|
36 |
-
|
37 |
-
for _, row in df.iterrows():
|
38 |
-
question = row['question']
|
39 |
-
explanation = row['explanation']
|
40 |
-
scores = eval(question, explanation)
|
41 |
-
commentary = write_evaluation_commentary(scores)[["Principle", "Score"]].transpose().to_dict()
|
42 |
-
results.append({**{'Question': question, 'Explanation': explanation}, **commentary})
|
43 |
-
|
44 |
-
result_df = pd.DataFrame(results)
|
45 |
-
return result_df
|
46 |
-
|
47 |
-
# Title of the application
|
48 |
-
st.title('Natural Language Explanation Demo')
|
49 |
-
|
50 |
-
# Check if password has been validated
|
51 |
-
if not st.session_state.get('password_correct', False):
|
52 |
-
check_password()
|
53 |
-
else:
|
54 |
-
st.sidebar.success("Password Verified. Proceed with the demo.")
|
55 |
-
st.header("Batch Evaluation of Questions and Explanations")
|
56 |
-
uploaded_file = st.file_uploader("Upload CSV file with columns 'question' and 'explanation'", type='csv')
|
57 |
-
|
58 |
-
if uploaded_file is not None:
|
59 |
-
if st.button('Evaluate Explanations'):
|
60 |
-
result_df = batch_evaluate(uploaded_file)
|
61 |
-
st.write('### Evaluated Results')
|
62 |
-
st.dataframe(result_df)
|
63 |
-
|
64 |
-
csv = result_df.to_csv(index=False)
|
65 |
-
st.download_button(
|
66 |
-
label="Download evaluation results as CSV",
|
67 |
-
data=csv,
|
68 |
-
file_name='evaluated_results.csv',
|
69 |
-
mime='text/csv'
|
70 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|