DmitrMakeev commited on
Commit
e8c1600
·
1 Parent(s): 4ac3518

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -22
app.py CHANGED
@@ -1,43 +1,39 @@
1
  import openai
2
- import json
 
3
 
4
- openai.api_key = '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'
5
-
6
- def openai_chat(prompt):
7
  completions = openai.Completion.create(
8
  engine="text-davinci-003",
9
- prompt=prompt + "The following is the prompt from the teacher working in the canvas infrastructure",
10
  max_tokens=1024,
11
  temperature=0.5,
12
  stop=[" Human:", " AI:"]
13
  )
14
-
15
  message = completions.choices[0].text
16
  return message.strip()
17
 
18
- def chatbot(input, history=None):
19
- if history is None:
20
- history = []
21
-
22
- output = openai_chat(input)
23
  history.append((input, output))
 
24
 
25
- # Write the chat history to a JSON file
26
- with open("chatbot_history.json", "w") as file:
27
- json.dump(history, file)
28
-
29
- return output, history
30
 
31
  iface = gr.Interface(
32
  fn=chatbot,
33
- inputs=["text", "textarray"],
34
- outputs=["text", "textarray"],
35
  examples=[
36
- ["Hello", []],
37
- ["How are you?", []],
 
 
38
  ],
39
- title="GPT-3 Text Chatbot",
40
- description="Chat with the GPT-3 text chatbot",
 
41
  )
42
 
43
  iface.launch()
 
1
  import openai
2
+ import gradio as gr
3
+ from gradio import HuggingFaceDatasetSaver
4
 
5
+ def openai_chat(prompt, api_key):
6
+ openai.api_key = api_key
 
7
  completions = openai.Completion.create(
8
  engine="text-davinci-003",
9
+ prompt=prompt+"The following is the prompt from teacher working in canvas infrastructure",
10
  max_tokens=1024,
11
  temperature=0.5,
12
  stop=[" Human:", " AI:"]
13
  )
 
14
  message = completions.choices[0].text
15
  return message.strip()
16
 
17
+ def chatbot(input, api_key, history=[]):
18
+ output = openai_chat(input, api_key)
 
 
 
19
  history.append((input, output))
20
+ return history, history
21
 
22
+ api_key_input = gr.inputs.Textbox(label="Ключ OpenAI API", type="password")
 
 
 
 
23
 
24
  iface = gr.Interface(
25
  fn=chatbot,
26
+ inputs=["text", api_key_input, 'state'],
27
+ outputs=["chatbot", 'state'],
28
  examples=[
29
+ ["Создай план маршрута поездки в Мадрид на 7 дней с семьей, при этом учитывая наличие туристических достопримечательностей и музеев.."],
30
+ ["Предложи варианты стратегий развития моего бизнеса: "],
31
+ ["Подробно опиши как в русском языке действует это правило: "],
32
+ ["Предложи решение этой математической задачи, с подробными комментариями к каждому действию: "],
33
  ],
34
+ cache_examples=False,
35
+ title="GPT-3 Модель: Text-davinci-003",
36
+ allow_flagging="manual"
37
  )
38
 
39
  iface.launch()