orchestration / app.py
bprzy's picture
Initial.
945c107
raw
history blame
1.48 kB
import os
import openai
import gradio as gr
openai.api_key = os.getenv("OPENAI_API_KEY")
start_sequence = "\nCoach:"
restart_sequence = "\nMe:"
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."
def completion_create(prompt):
response = openai.Completion.create(
model = "text-davinci-003",
prompt=prompt,
temperature=0.9,
max_tokens=150,
top_p=1,
frequency_penalty=0,
presence_penalty=0.6,
stop=[" Coach:", " Me:"])
print("Raw response: ")
print(response)
return response.choices[0].text
def chat_clone(input, history):
history = history or []
s = list(sum(history, ()))
print(s)
s.append(input)
inp = ' '.join(s)
output = completion_create(inp)
if (len(output) < 5): print("ERROR, short output")
print(output)
history.append((input, output))
return history, history
block = gr.Blocks(css="main.css", title="Coaching Demo")
with block:
gr.Markdown("""<h1><center>Coaching Demo</center></h1>""")
chatbot = gr.Chatbot()
input = gr.Textbox(placeholder=None,value="")
state = gr.State()
input.submit(chat_clone, inputs=[input, state], outputs=[chatbot, state])
submit = gr.Button("Ask")
submit.click(chat_clone, inputs=[input, state], outputs=[chatbot, state])
block.launch(share=False,debug=True)