HemanM commited on
Commit
1e3a2f8
·
verified ·
1 Parent(s): e695177

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,22 +1,27 @@
1
  import gradio as gr
2
  from inference import predict
3
  from logger import log_feedback_to_firebase
4
- import openai
5
- import os
6
  from watchdog import manual_retrain
7
  from dashboard import render_dashboard
 
 
8
 
9
- openai.api_key = os.environ["OPENAI_API_KEY"] # Add this secret in your Hugging Face Space
 
10
 
11
  def gpt_predict(goal, sol1, sol2):
12
- prompt = f"You're solving a commonsense reasoning problem. Choose the better solution to achieve the goal.\n\nGoal: {goal}\n\nOption 1: {sol1}\nOption 2: {sol2}\n\nWhich option is better? Reply with only 'Solution 1' or 'Solution 2'."
 
 
 
 
13
  try:
14
- response = openai.ChatCompletion.create(
15
  model="gpt-3.5-turbo",
16
  messages=[{"role": "user", "content": prompt}],
17
  temperature=0
18
  )
19
- reply = response.choices[0].message["content"]
20
  return "Solution 1" if "1" in reply else "Solution 2"
21
  except Exception as e:
22
  return f"GPT Error: {str(e)}"
 
1
  import gradio as gr
2
  from inference import predict
3
  from logger import log_feedback_to_firebase
 
 
4
  from watchdog import manual_retrain
5
  from dashboard import render_dashboard
6
+ from openai import OpenAI
7
+ import os
8
 
9
+ # Initialize OpenAI client
10
+ client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) # Add this secret in your HF Space
11
 
12
  def gpt_predict(goal, sol1, sol2):
13
+ prompt = (
14
+ f"You're solving a commonsense reasoning problem. Choose the better solution to achieve the goal.\n\n"
15
+ f"Goal: {goal}\n\nOption 1: {sol1}\nOption 2: {sol2}\n\n"
16
+ f"Which option is better? Reply with only 'Solution 1' or 'Solution 2'."
17
+ )
18
  try:
19
+ response = client.chat.completions.create(
20
  model="gpt-3.5-turbo",
21
  messages=[{"role": "user", "content": prompt}],
22
  temperature=0
23
  )
24
+ reply = response.choices[0].message.content
25
  return "Solution 1" if "1" in reply else "Solution 2"
26
  except Exception as e:
27
  return f"GPT Error: {str(e)}"