Spaces:
Configuration error
Configuration error
Initial.
Browse files- app.py +50 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import openai
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
6 |
+
|
7 |
+
start_sequence = "\nCoach:"
|
8 |
+
restart_sequence = "\nMe:"
|
9 |
+
|
10 |
+
prompt = "The following is a conversation with an instructor. The instructor is an expert in opportunity cost. You will act as the instructor, I will be the student."
|
11 |
+
|
12 |
+
def completion_create(prompt):
|
13 |
+
|
14 |
+
response = openai.Completion.create(
|
15 |
+
model = "text-davinci-003",
|
16 |
+
prompt=prompt,
|
17 |
+
temperature=0.9,
|
18 |
+
max_tokens=150,
|
19 |
+
top_p=1,
|
20 |
+
frequency_penalty=0,
|
21 |
+
presence_penalty=0.6,
|
22 |
+
stop=[" Coach:", " Me:"])
|
23 |
+
print("Raw response: ")
|
24 |
+
print(response)
|
25 |
+
return response.choices[0].text
|
26 |
+
|
27 |
+
def chat_clone(input, history):
|
28 |
+
history = history or []
|
29 |
+
s = list(sum(history, ()))
|
30 |
+
print(s)
|
31 |
+
s.append(input)
|
32 |
+
inp = ' '.join(s)
|
33 |
+
output = completion_create(inp)
|
34 |
+
if (len(output) < 5): print("ERROR, short output")
|
35 |
+
print(output)
|
36 |
+
history.append((input, output))
|
37 |
+
return history, history
|
38 |
+
|
39 |
+
block = gr.Blocks(css="main.css", title="Coaching Demo")
|
40 |
+
|
41 |
+
with block:
|
42 |
+
gr.Markdown("""<h1><center>Coaching Demo</center></h1>""")
|
43 |
+
chatbot = gr.Chatbot()
|
44 |
+
input = gr.Textbox(placeholder=None,value="")
|
45 |
+
state = gr.State()
|
46 |
+
input.submit(chat_clone, inputs=[input, state], outputs=[chatbot, state])
|
47 |
+
submit = gr.Button("Ask")
|
48 |
+
submit.click(chat_clone, inputs=[input, state], outputs=[chatbot, state])
|
49 |
+
|
50 |
+
block.launch(share=False,debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
openai
|