DmitrMakeev commited on
Commit
cfd68a6
1 Parent(s): 1e7cbdc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -1,16 +1,14 @@
1
-
2
  import openai
3
  import gradio as gr
4
  from gradio import HuggingFaceDatasetSaver
5
 
 
6
 
7
-
8
- def openai_chat(prompt, api_key):
9
- openai.api_key = api_key
10
  completions = openai.Completion.create(
11
  engine="text-davinci-003",
12
  prompt=prompt+"The following is the prompt from teacher working in canvas infrastructure",
13
- max_tokens=2000,
14
  temperature=0.5,
15
  stop=[" Human:", " AI:"]
16
  )
@@ -18,11 +16,13 @@ def openai_chat(prompt, api_key):
18
  message = completions.choices[0].text
19
  return message.strip()
20
 
21
- def chatbot(input, history=[], api_key=''):
22
- output = openai_chat(input, api_key)
23
  history.append((input, output))
24
  return history, history
25
 
 
 
26
  api_key_input = gr.inputs.Textbox(label="Ключ OpenAI API", type="password")
27
  iface = gr.Interface(fn=chatbot,
28
  inputs=["text", 'state', api_key_input],
@@ -35,7 +35,7 @@ iface = gr.Interface(fn=chatbot,
35
  ],
36
  cache_examples=False,
37
  title="GPT-3 Модель: Text-davinci-003",
38
-
39
- allow_flagging="manual")
40
 
41
  iface.launch()
 
 
1
  import openai
2
  import gradio as gr
3
  from gradio import HuggingFaceDatasetSaver
4
 
5
+ openai.api_key ='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'
6
 
7
+ def openai_chat(prompt):
 
 
8
  completions = openai.Completion.create(
9
  engine="text-davinci-003",
10
  prompt=prompt+"The following is the prompt from teacher working in canvas infrastructure",
11
+ max_tokens=1024,
12
  temperature=0.5,
13
  stop=[" Human:", " AI:"]
14
  )
 
16
  message = completions.choices[0].text
17
  return message.strip()
18
 
19
+ def chatbot(input, history=[]):
20
+ output = openai_chat(input)
21
  history.append((input, output))
22
  return history, history
23
 
24
+ saver = HuggingFaceDatasetSaver("chatbot_history.jsonl") # Создаем объект сохранения истории
25
+
26
  api_key_input = gr.inputs.Textbox(label="Ключ OpenAI API", type="password")
27
  iface = gr.Interface(fn=chatbot,
28
  inputs=["text", 'state', api_key_input],
 
35
  ],
36
  cache_examples=False,
37
  title="GPT-3 Модель: Text-davinci-003",
38
+ allow_flagging="manual",
39
+ datasets=[saver]) # Передаем saver в качестве аргумента, чтобы история сохранялась
40
 
41
  iface.launch()