Zekun Wu commited on
Commit
8766924
·
1 Parent(s): 0da3235
Files changed (1) hide show
  1. pages/2_batch_evaluation.py +14 -6
pages/2_batch_evaluation.py CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
3
  from util.evaluator import evaluator, write_evaluation_commentary
4
  import os
5
 
 
6
  def check_password():
7
  with st.sidebar:
8
  password_input = st.text_input("Enter Password:", type="password")
@@ -14,16 +15,19 @@ def check_password():
14
  else:
15
  st.error("Incorrect Password, please try again.")
16
 
 
17
  def batch_evaluate(uploaded_file):
18
- # Read the uploaded CSV file into DataFrame
19
  df = pd.read_csv(uploaded_file)
20
- eval_instance = evaluator('gpt4-1106') # Using fixed model name for simplicity
 
21
  results = []
22
 
23
- # Process each row in the DataFrame
24
- for _, row in df.iterrows():
25
- question = row['question']
26
- explanation = row['explanation']
 
 
27
  scores = eval_instance(question, explanation) # Evaluate using the evaluator
28
  commentary_details = write_evaluation_commentary(scores) # Generate commentary based on scores
29
  results.append({
@@ -32,8 +36,12 @@ def batch_evaluate(uploaded_file):
32
  **{detail['Principle']: detail['Score'] for detail in commentary_details}
33
  })
34
 
 
 
 
35
  return pd.DataFrame(results)
36
 
 
37
  st.title('Natural Language Explanation Demo')
38
 
39
  if 'password_verified' not in st.session_state or not st.session_state['password_verified']:
 
3
  from util.evaluator import evaluator, write_evaluation_commentary
4
  import os
5
 
6
+
7
  def check_password():
8
  with st.sidebar:
9
  password_input = st.text_input("Enter Password:", type="password")
 
15
  else:
16
  st.error("Incorrect Password, please try again.")
17
 
18
+
19
  def batch_evaluate(uploaded_file):
 
20
  df = pd.read_csv(uploaded_file)
21
+ eval_instance = evaluator('gpt4-1106') # Assuming fixed model name for simplicity
22
+ total_rows = len(df)
23
  results = []
24
 
25
+ # Add a progress bar
26
+ progress_bar = st.progress(0)
27
+
28
+ for index, row in enumerate(df.itertuples(), start=1):
29
+ question = row.question
30
+ explanation = row.explanation
31
  scores = eval_instance(question, explanation) # Evaluate using the evaluator
32
  commentary_details = write_evaluation_commentary(scores) # Generate commentary based on scores
33
  results.append({
 
36
  **{detail['Principle']: detail['Score'] for detail in commentary_details}
37
  })
38
 
39
+ # Update progress bar
40
+ progress_bar.progress(index / total_rows)
41
+
42
  return pd.DataFrame(results)
43
 
44
+
45
  st.title('Natural Language Explanation Demo')
46
 
47
  if 'password_verified' not in st.session_state or not st.session_state['password_verified']: