Timothy-Vinzent commited on
Commit
07b4a92
·
verified ·
1 Parent(s): 0b94c8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -31
app.py CHANGED
@@ -4,8 +4,6 @@ from datetime import datetime
4
 
5
  import gradio as gr
6
  import openai
7
- import gspread
8
- from oauth2client.service_account import ServiceAccountCredentials
9
 
10
  # Set OpenAI API key from an environment variable.
11
  openai.api_key = os.environ["OPENAI_API_KEY"]
@@ -31,26 +29,6 @@ def get_evaluation_questions():
31
  # Load the evaluation questions once at startup.
32
  EVALUATION_QUESTIONS = get_evaluation_questions()
33
 
34
- def init_sheet():
35
- """
36
- Initializes and returns the Google Sheet.
37
- The sheet name is taken from the SHEET_NAME environment variable,
38
- defaulting to "Prompt Evaluations" if not set.
39
-
40
- Ensure that your service account credentials (credentials.json)
41
- are available and that the sheet is shared with the service account's email.
42
- """
43
- scopes = [
44
- "https://spreadsheets.google.com/feeds",
45
- "https://www.googleapis.com/auth/spreadsheets",
46
- "https://www.googleapis.com/auth/drive"
47
- ]
48
- creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scopes)
49
- client = gspread.authorize(creds)
50
- sheet_name = os.environ.get("SHEET_NAME", "Prompt Evaluations")
51
- sheet = client.open(sheet_name).sheet1
52
- return sheet
53
-
54
  def sanitize_input(text):
55
  """
56
  Sanitizes input to prevent harmful content and limits its length.
@@ -65,7 +43,7 @@ def evaluate_prompt(email, name, system_prompt):
65
  - Uses the provided system prompt to generate a response with GPT-4o Mini.
66
  - Checks if the expected substring is present.
67
  - Computes an aggregate score.
68
- Logs the user's email, name, system prompt, and score to a Google Sheet.
69
  """
70
  # Sanitize the inputs.
71
  email = sanitize_input(email)
@@ -105,14 +83,6 @@ def evaluate_prompt(email, name, system_prompt):
105
 
106
  result_details = "\n".join(responses)
107
 
108
- try:
109
- sheet = init_sheet()
110
- timestamp = datetime.now().isoformat()
111
- row = [timestamp, email, name, score, system_prompt]
112
- sheet.append_row(row)
113
- except Exception as err:
114
- print("Error writing to Google Sheet:", err)
115
-
116
  return f"Your evaluation score is {score} out of {len(EVALUATION_QUESTIONS)}.\n\nDetails:\n{result_details}"
117
 
118
  def build_interface():
 
4
 
5
  import gradio as gr
6
  import openai
 
 
7
 
8
  # Set OpenAI API key from an environment variable.
9
  openai.api_key = os.environ["OPENAI_API_KEY"]
 
29
  # Load the evaluation questions once at startup.
30
  EVALUATION_QUESTIONS = get_evaluation_questions()
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  def sanitize_input(text):
33
  """
34
  Sanitizes input to prevent harmful content and limits its length.
 
43
  - Uses the provided system prompt to generate a response with GPT-4o Mini.
44
  - Checks if the expected substring is present.
45
  - Computes an aggregate score.
46
+ Returns the evaluation results as a string.
47
  """
48
  # Sanitize the inputs.
49
  email = sanitize_input(email)
 
83
 
84
  result_details = "\n".join(responses)
85
 
 
 
 
 
 
 
 
 
86
  return f"Your evaluation score is {score} out of {len(EVALUATION_QUESTIONS)}.\n\nDetails:\n{result_details}"
87
 
88
  def build_interface():