jvictoria commited on
Commit
f02087b
0 Parent(s):

Duplicate from jvictoria/EssayChecker

Browse files
Files changed (4) hide show
  1. .gitattributes +34 -0
  2. README.md +13 -0
  3. app.py +51 -0
  4. requirements.txt +2 -0
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz filter=lfs diff=lfs merge=lfs -text
32
+ *.zip filter=lfs diff=lfs merge=lfs -text
33
+ *.zst filter=lfs diff=lfs merge=lfs -text
34
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: EssayChecker
3
+ emoji: 📊
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: 3.23.0
8
+ app_file: app.py
9
+ pinned: false
10
+ duplicated_from: jvictoria/EssayChecker
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import gradio
3
+ import os
4
+ import re
5
+
6
+ openai.api_key = os.environ.get("API_TOKEN")
7
+
8
+ messages = [{"role": "system", "content": "You are an education expert who can correct essays. You are bilingual in English and Japanese"}]
9
+
10
+ MAX_TOKENS = 4096
11
+ MAX_HISTORY = 1
12
+
13
+ def CustomChatGPT(user_input):
14
+ global messages
15
+ essay_keywords = ["essay", "エッセイ", "論文"]
16
+ action_keywords = ["write", "make", "create", "生成", "作成", "書く"]
17
+
18
+ if any(re.search(f"{action_kw}.*{essay_kw}", user_input.lower()) for action_kw in action_keywords for essay_kw in essay_keywords):
19
+ return "I'm sorry, I cannot write an essay for you."
20
+
21
+ # Clear the messages list before adding new messages
22
+ messages = [{"role": "system", "content": "You are an education expert who can correct essays. You are bilingual in English and Japanese"}]
23
+
24
+ user_message = {"role": "user", "content": f"Step 1, find make grammar and spelling and corrections. Step 2, show the corrected version. Step 3, Explain in detail all the errors from what I originally wrote. Put each explanation in a bullet point: [{user_input}]"}
25
+
26
+ messages.append(user_message)
27
+
28
+ while True:
29
+ response = openai.ChatCompletion.create(
30
+ model="gpt-3.5-turbo",
31
+ messages=messages
32
+ )
33
+
34
+ total_tokens = response['usage']['total_tokens']
35
+ if total_tokens < MAX_TOKENS:
36
+ break
37
+
38
+ ChatGPT_reply = response["choices"][0]["message"]["content"]
39
+ messages.append({"role": "assistant", "content": ChatGPT_reply})
40
+
41
+ return ChatGPT_reply
42
+
43
+ # Add text instructions on top of the input and output boxes
44
+ input_text = "ここに訂正してほしい英語の作文を置いてください。そして「Submit」を押してください:"
45
+ output_text = "訂正と説明はここに表示されます:"
46
+ instructions = "このアプリケーションは、文法と綴りをチェックするために使用できます。アプリは、修正した作文を提供し、それに続いて修正の説明を示します。アプリは、1つのパラグラフずつ入力する場合に最適に機能します。例えば、3つのパラグラフから成る作文をチェックしたい場合は、それぞれのパラグラフを「Submit」してください。つまり、プログラムを3回実行し、各パラグラフごとに1回ずつ実行してください。"
47
+
48
+ # Modify the Gradio interface to include the text instructions and image
49
+ demo = gradio.Interface(fn=CustomChatGPT, inputs=gradio.inputs.Textbox(lines=5, label=input_text), outputs=gradio.outputs.Textbox(label=output_text), title="Teacher Jihan's Checking Assistant", description=instructions)
50
+
51
+ demo.launch(share=False, debug=True)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ openai>=0.27.0
2
+ gradio==3.26.0