Spaces:
Runtime error
Runtime error
DmitrMakeev
commited on
Commit
•
2601ee6
1
Parent(s):
0dcb7e1
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,9 @@
|
|
1 |
import openai
|
2 |
import gradio as gr
|
3 |
from gradio import HuggingFaceDatasetSaver
|
4 |
-
api_k = 'sk'
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
with gr.Blocks() as myface:
|
9 |
-
with gr.Row():
|
10 |
-
api_k = gr.Textbox(label="Ключ OpenAI API", type="password")
|
11 |
-
openai.api_key = api_k
|
12 |
-
|
13 |
-
|
14 |
-
def openai_chat(prompt):
|
15 |
completions = openai.Completion.create(
|
16 |
engine="text-davinci-003",
|
17 |
prompt=prompt+"The following is the prompt from teacher working in canvas infrastructure",
|
@@ -19,23 +11,29 @@ def openai_chat(prompt):
|
|
19 |
temperature=0.5,
|
20 |
stop=[" Human:", " AI:"]
|
21 |
)
|
22 |
-
|
23 |
message = completions.choices[0].text
|
24 |
return message.strip()
|
25 |
|
26 |
-
def chatbot(input, history=[]):
|
27 |
-
output = openai_chat(input)
|
28 |
history.append((input, output))
|
29 |
return history, history
|
30 |
|
31 |
-
gr.
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
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()
|