kavansaun commited on
Commit
85cb002
·
verified ·
1 Parent(s): 7a645bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -35,11 +35,10 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
35
  repo.create_file(filename, "Saving" + filename, "")
36
 
37
  return gr.TextArea(new_id,visible=False) # Returning the "TextArea" object with what we want. Set visible to True if you want the id to appear when its made.
38
- def user_prompt(inputs):
39
- user_dictionary[user_id].append({"role": "user", "content": inputs}) # This adds the input from the user and saves it to the history before we do anything else.
40
 
41
  def predict_prompt(inputs, user_id): # This function creates a response for the chatbot to respond with.
42
-
 
43
  time.sleep(5) # This pauses the function for the alloted amount of time (ex: time.sleep(5) -> pause for 5 seconds) *this doesnt account for the time it takes for the bot to create a response, so the bots overall response time will be noticably higher than the amount of time you put in*
44
 
45
  create_prompt = openai.ChatCompletion.create( #Asking openai for a prompt based on the current message history.
@@ -82,6 +81,6 @@ with gr.Blocks(theme=gr.themes.Monochrome(),css="footer{display:none !important}
82
  Chatbot = gr.Chatbot(label="Anonymous User",layout=['bubble']) # Creating a gradio-chatbot User Interface with the label "Anonymous User".
83
 
84
  txt = gr.Textbox(show_label=False, placeholder = initial_message,container=False)
85
- txt.submit([predict_prompt,user_prompt], [[txt, user_id],[txt]], Chatbot) # Adding the messages into the row with gradio.
86
 
87
  chatblock.launch() # launch!
 
35
  repo.create_file(filename, "Saving" + filename, "")
36
 
37
  return gr.TextArea(new_id,visible=False) # Returning the "TextArea" object with what we want. Set visible to True if you want the id to appear when its made.
 
 
38
 
39
  def predict_prompt(inputs, user_id): # This function creates a response for the chatbot to respond with.
40
+ user_dictionary[user_id].append({"role": "user", "content": inputs}) # This adds the input from the user and saves it to the history before we do anything else.
41
+
42
  time.sleep(5) # This pauses the function for the alloted amount of time (ex: time.sleep(5) -> pause for 5 seconds) *this doesnt account for the time it takes for the bot to create a response, so the bots overall response time will be noticably higher than the amount of time you put in*
43
 
44
  create_prompt = openai.ChatCompletion.create( #Asking openai for a prompt based on the current message history.
 
81
  Chatbot = gr.Chatbot(label="Anonymous User",layout=['bubble']) # Creating a gradio-chatbot User Interface with the label "Anonymous User".
82
 
83
  txt = gr.Textbox(show_label=False, placeholder = initial_message,container=False)
84
+ txt.submit(predict_prompt, [txt, user_id], Chatbot) # Adding the messages into the row with gradio.
85
 
86
  chatblock.launch() # launch!