Spaces:
Sleeping
Sleeping
Trenton Potter
commited on
Commit
·
d56b284
1
Parent(s):
a8a2d3f
Hit openai endpoint
Browse files
app.py
CHANGED
@@ -1,7 +1,36 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def grade_essay(essay):
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
|
7 |
demo = gr.Interface(fn=grade_essay, inputs="text", outputs="text")
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
import os
|
4 |
+
|
5 |
+
|
6 |
+
MODEL = "gpt-3.5-turbo"
|
7 |
+
|
8 |
+
try:
|
9 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
10 |
+
except:
|
11 |
+
print("Set the OPENAI_API_KEY environment variable")
|
12 |
+
exit()
|
13 |
+
|
14 |
+
def get_prompt(essay):
|
15 |
+
return f"""
|
16 |
+
Provide an estimate score and sub-scores for the following ACT writing sample using the ACT scoring rubric.
|
17 |
+
For each sub-score also provide one example of support and one example of what could be improved.
|
18 |
+
Each score should be a single number with one decimal point of accuracy and not a range.
|
19 |
+
This is the provided writing sample:
|
20 |
+
"{essay}"
|
21 |
+
"""
|
22 |
+
|
23 |
+
|
24 |
|
25 |
def grade_essay(essay):
|
26 |
+
response = openai.ChatCompletion.create(
|
27 |
+
model=MODEL,
|
28 |
+
messages=[{"role":"user", "content":get_prompt(essay)}],
|
29 |
+
temperature=1,
|
30 |
+
max_tokens=1000
|
31 |
+
)
|
32 |
+
|
33 |
+
return response['choices'][0]['message']['content']
|
34 |
|
35 |
|
36 |
demo = gr.Interface(fn=grade_essay, inputs="text", outputs="text")
|