essay_grader / app.py
Trenton Potter
Hit openai endpoint
d56b284
raw
history blame
974 Bytes
import gradio as gr
import openai
import os
MODEL = "gpt-3.5-turbo"
try:
openai.api_key = os.getenv("OPENAI_API_KEY")
except:
print("Set the OPENAI_API_KEY environment variable")
exit()
def get_prompt(essay):
return f"""
Provide an estimate score and sub-scores for the following ACT writing sample using the ACT scoring rubric.
For each sub-score also provide one example of support and one example of what could be improved.
Each score should be a single number with one decimal point of accuracy and not a range.
This is the provided writing sample:
"{essay}"
"""
def grade_essay(essay):
response = openai.ChatCompletion.create(
model=MODEL,
messages=[{"role":"user", "content":get_prompt(essay)}],
temperature=1,
max_tokens=1000
)
return response['choices'][0]['message']['content']
demo = gr.Interface(fn=grade_essay, inputs="text", outputs="text")
demo.launch()