Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,19 @@
|
|
| 1 |
import openai
|
| 2 |
import gradio
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
openai.api_key = os.environ.get("API_TOKEN")
|
| 6 |
|
| 7 |
messages = [{"role": "system", "content": "You are an education expert who can correct essays. You are bilingual in English and Japanese"}]
|
| 8 |
|
| 9 |
def CustomChatGPT(user_input):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
messages.append({"role": "user", "content": f"ๆฌกใฎ่ฑๆ[ใใญในใ]ใง็งใ็ฏใใๆๆณ็ใชใในใใในใฆ่ชฌๆใใฆใใ ใใใ็งใฏ้ซๆ ก็ใฎESLๅญฆ็ใชใฎใงใใใใใใใฎ้้ใใๆฅๆฌ่ชใง่ฉณใใ่ชฌๆใใฆใใ ใใใ [{user_input}]"})
|
| 11 |
response = openai.ChatCompletion.create(
|
| 12 |
model="gpt-3.5-turbo",
|
|
@@ -18,4 +25,4 @@ def CustomChatGPT(user_input):
|
|
| 18 |
|
| 19 |
demo = gradio.Interface(fn=CustomChatGPT, inputs="textarea", outputs="text", title="Teacher Jihan")
|
| 20 |
|
| 21 |
-
demo.launch(share=False, debug=True)
|
|
|
|
| 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 |
def CustomChatGPT(user_input):
|
| 11 |
+
essay_keywords = ["essay", "ใจใใปใค", "่ซๆ"]
|
| 12 |
+
action_keywords = ["write", "make", "create", "็ๆ", "ไฝๆ", "ๆธใ"]
|
| 13 |
+
|
| 14 |
+
if any(re.search(f"{action_kw}.*{essay_kw}", user_input.lower()) for action_kw in action_keywords for essay_kw in essay_keywords):
|
| 15 |
+
return "I'm sorry, I cannot write an essay for you."
|
| 16 |
+
|
| 17 |
messages.append({"role": "user", "content": f"ๆฌกใฎ่ฑๆ[ใใญในใ]ใง็งใ็ฏใใๆๆณ็ใชใในใใในใฆ่ชฌๆใใฆใใ ใใใ็งใฏ้ซๆ ก็ใฎESLๅญฆ็ใชใฎใงใใใใใใใฎ้้ใใๆฅๆฌ่ชใง่ฉณใใ่ชฌๆใใฆใใ ใใใ [{user_input}]"})
|
| 18 |
response = openai.ChatCompletion.create(
|
| 19 |
model="gpt-3.5-turbo",
|
|
|
|
| 25 |
|
| 26 |
demo = gradio.Interface(fn=CustomChatGPT, inputs="textarea", outputs="text", title="Teacher Jihan")
|
| 27 |
|
| 28 |
+
demo.launch(share=False, debug=True)
|