Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
|
|
10 |
|
11 |
def gpt_predict(goal, sol1, sol2):
|
12 |
-
prompt =
|
|
|
|
|
|
|
|
|
13 |
try:
|
14 |
-
response =
|
15 |
model="gpt-3.5-turbo",
|
16 |
messages=[{"role": "user", "content": prompt}],
|
17 |
temperature=0
|
18 |
)
|
19 |
-
reply = response.choices[0].message
|
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)}"
|