Spaces:
Sleeping
Sleeping
Commit
·
cdcdde4
1
Parent(s):
8a7777a
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,25 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
demo = gr.Interface(
|
16 |
-
fn=generate,
|
17 |
-
inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
|
18 |
-
outputs=gr.outputs.Textbox(label="Generated Text"),
|
19 |
-
examples=examples
|
20 |
-
)
|
21 |
-
|
22 |
-
demo.launch()
|
|
|
1 |
+
import openai
|
2 |
import gradio as gr
|
3 |
+
openai.api_key ='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'
|
4 |
+
def openai_chat(prompt):
|
5 |
+
completions = openai.Completion.create(
|
6 |
+
engine="text-davinci-003",
|
7 |
+
prompt=prompt+"The following is the prompt from teacher working in canvas infrastructure",
|
8 |
+
max_tokens=1024,
|
9 |
+
n=1,
|
10 |
+
temperature=0.5,
|
11 |
+
frequency_penalty=0,
|
12 |
+
presence_penalty=0.6,
|
13 |
+
stop=[" Human:", " AI:"]
|
14 |
+
)
|
15 |
|
16 |
+
message = completions.choices[0].text
|
17 |
+
return message.strip()
|
18 |
+
def chatbot(input, history=[]):
|
19 |
+
output = openai_chat(input)
|
20 |
+
history.append((input, output))
|
21 |
+
return history, history
|
22 |
+
gr.Interface(fn = chatbot,
|
23 |
+
inputs = ["text",'state'],
|
24 |
+
outputs = ["chatbot",'state'],
|
25 |
+
allow_flagging="manual").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|