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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -22
app.py CHANGED
@@ -1,9 +1,9 @@
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",
@@ -11,29 +11,23 @@ def openai_chat(prompt, api_key):
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()
 
1
  import openai
2
  import gradio as gr
3
  from gradio import HuggingFaceDatasetSaver
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 teacher working in canvas infrastructure",
 
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=[]):
19
+ output = openai_chat(input)
20
  history.append((input, output))
21
  return history, history
22
 
23
+ gr.Interface(fn = chatbot,
24
+ inputs = ["text",'state'],
25
+ outputs = ["chatbot",'state'],
26
+ examples = [
27
+ ["Armar un itinerario para viajar a Madrid, por 7 días, con familia, tener en cuenta que quiero hacer puntos turísticos y museos."],
28
+ ["Armar un plan de viaje para 10 días en Italia."],
29
+ ["Conseguir el vuelo más barato desde Buenos Aires a Nueva York, para un viaje de 7 días en marzo de 2023."],
30
+ ],
31
+ cache_examples=False,
32
+ title="Demo app",
33
+ allow_flagging="manual").launch()