jvictoria commited on
Commit
5313308
·
1 Parent(s): e1d2087

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -35
app.py CHANGED
@@ -1,8 +1,7 @@
1
- import openai
2
  import gradio
3
  import os
4
  import re
5
- from gradio.components import Textbox, TextboxOutput
6
 
7
  openai.api_key = os.environ.get("API_TOKEN")
8
 
@@ -27,40 +26,16 @@ def CustomChatGPT(user_input):
27
  messages.append(user_message)
28
 
29
  while True:
30
- response = openai.Completion.create(
31
- engine="text-davinci-002",
32
- prompt=None,
33
- temperature=0.7,
34
- max_tokens=MAX_TOKENS,
35
- n = 1,
36
- stop = None,
37
- frequency_penalty = 0,
38
- presence_penalty = 0,
39
- timeout = None,
40
- logprobs = None,
41
- logit_bias = None,
42
- model="text-davinci-002",
43
- prompt_id=None,
44
- input_type=None,
45
- output_prefix=None,
46
- output_suffix=None,
47
- state=None,
48
- **{
49
- "history": messages,
50
- "stream": False,
51
- "stop": None,
52
- "n": 1,
53
- "temperature": 0.7,
54
- "presence_penalty": 0,
55
- "frequency_penalty": 0
56
- }
57
  )
58
 
59
- total_tokens = response['total_characters']
60
  if total_tokens < MAX_TOKENS:
61
  break
62
 
63
- ChatGPT_reply = response.choices[0].text
64
  messages.append({"role": "assistant", "content": ChatGPT_reply})
65
 
66
  return ChatGPT_reply
@@ -69,9 +44,8 @@ def CustomChatGPT(user_input):
69
  input_text = "ここに訂正してほしい英語の作文を置いてください。そして「Submit」を押してください:"
70
  output_text = "訂正と説明はここに表示されます:"
71
  instructions = "このアプリケーションは、文法と綴りをチェックするために使用できます。アプリは、修正された作文を提供し、それに続いて修正の説明を示します。アプリは、1つのパラグラフずつ入力する場合に最適に機能します。例えば、3つのパラグラフから成る作文をチェックしたい場合は、それぞれのパラグラフを別々に提出してください。つまり、プログラムを3回実行し、各パラグラフごとに1回ずつ実行してください。"
 
72
  # Modify the Gradio interface to include the text instructions and image
73
- demo = gradio.Interface(fn=CustomChatGPT, inputs=Textbox(lines=5, label=input_text),
74
- outputs=TextboxOutput(label=output_text),
75
- title="Teacher Jihan's Checking Assistant", description=instructions)
76
 
77
- demo.launch(share=False, debug=True)
 
1
+ mport openai
2
  import gradio
3
  import os
4
  import re
 
5
 
6
  openai.api_key = os.environ.get("API_TOKEN")
7
 
 
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
 
44
  input_text = "ここに訂正してほしい英語の作文を置いてください。そして「Submit」を押してください:"
45
  output_text = "訂正と説明はここに表示されます:"
46
  instructions = "このアプリケーションは、文法と綴りをチェックするために使用できます。アプリは、修正された作文を提供し、それに続いて修正の説明を示します。アプリは、1つのパラグラフずつ入力する場合に最適に機能します。例えば、3つのパラグラフから成る作文をチェックしたい場合は、それぞれのパラグラフを別々に提出してください。つまり、プログラムを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=True, debug=True)