Spaces:
Runtime error
Runtime error
jpcabangon
commited on
Commit
•
a634c9b
1
Parent(s):
f87eabc
'added ChatGPT section and openai package requirement'
Browse files- app.py +37 -0
- requirements.txt +2 -1
app.py
CHANGED
@@ -12,6 +12,8 @@ import pandas as pd
|
|
12 |
|
13 |
from model import BertLightningModel
|
14 |
|
|
|
|
|
15 |
#######################################################################################################################
|
16 |
current_path = os.path.abspath(os.path.dirname(__file__))
|
17 |
|
@@ -109,6 +111,18 @@ def read_pdf(file):
|
|
109 |
|
110 |
return all_page_text
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
def main():
|
113 |
head_col = st.columns([1,8])
|
114 |
with head_col[0]:
|
@@ -307,6 +321,29 @@ def main():
|
|
307 |
final_df_ex = grades_df_ex.merge(evals_df_ex, on='Filename')
|
308 |
st.dataframe(final_df_ex)
|
309 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
310 |
|
311 |
if __name__ == '__main__':
|
312 |
main()
|
|
|
12 |
|
13 |
from model import BertLightningModel
|
14 |
|
15 |
+
import openai
|
16 |
+
|
17 |
#######################################################################################################################
|
18 |
current_path = os.path.abspath(os.path.dirname(__file__))
|
19 |
|
|
|
111 |
|
112 |
return all_page_text
|
113 |
|
114 |
+
def openai_chat(prompt, model, max_tokens):
|
115 |
+
response = openai.Completion.create(
|
116 |
+
engine=model,
|
117 |
+
prompt=prompt,
|
118 |
+
max_tokens=max_tokens,
|
119 |
+
n=1,
|
120 |
+
stop=None,
|
121 |
+
temperature=0.7,
|
122 |
+
)
|
123 |
+
message = response.choices[0].text.strip()
|
124 |
+
return message
|
125 |
+
|
126 |
def main():
|
127 |
head_col = st.columns([1,8])
|
128 |
with head_col[0]:
|
|
|
321 |
final_df_ex = grades_df_ex.merge(evals_df_ex, on='Filename')
|
322 |
st.dataframe(final_df_ex)
|
323 |
|
324 |
+
# ChatGPT Evaluation Section
|
325 |
+
st.subheader("")
|
326 |
+
st.markdown("***")
|
327 |
+
st.subheader("ChatGPT Evaluation")
|
328 |
+
openai.api_key = "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"
|
329 |
+
|
330 |
+
chatgpt_prompts = []
|
331 |
+
chatgpt_responses = []
|
332 |
+
for answer in ex_essays:
|
333 |
+
prompt = f"Evaluate the following essay using the Criterion: [cohesion, syntax, vocabulary, phraseology, grammar, conventions]. " \
|
334 |
+
f"Use a {min_score_ex} to {max_score_ex} score range for each, and provide one final score using the same score range " \
|
335 |
+
f"and summarized feedback. Essay: \n"
|
336 |
+
prompt += answer
|
337 |
+
response = openai_chat(prompt=prompt, model="text-davinci-002", max_tokens=1024)
|
338 |
+
chatgpt_prompts.append(prompt)
|
339 |
+
chatgpt_responses.append(response)
|
340 |
+
|
341 |
+
chatgpt_ta_val = ""
|
342 |
+
for i, val in enumerate(chatgpt_prompts):
|
343 |
+
chatgpt_ta_val = chatgpt_ta_val + val + "\n" + chatgpt_responses[i] + "\n"
|
344 |
+
chatgpt_ta = st.text_area("ChatGPT", placeholder="ChatGPT's evaluations will display here.",
|
345 |
+
value=chatgpt_ta_val, height=500, disabled=True)
|
346 |
+
|
347 |
|
348 |
if __name__ == '__main__':
|
349 |
main()
|
requirements.txt
CHANGED
@@ -9,4 +9,5 @@ seaborn==0.12.1
|
|
9 |
pytorch-lightning==1.8.3
|
10 |
sentencepiece==0.1.97
|
11 |
docx2txt==0.8
|
12 |
-
pypdf2==3.0.1
|
|
|
|
9 |
pytorch-lightning==1.8.3
|
10 |
sentencepiece==0.1.97
|
11 |
docx2txt==0.8
|
12 |
+
pypdf2==3.0.1
|
13 |
+
openai
|