dylanmeca commited on
Commit
5ce9388
·
1 Parent(s): 06c8b02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -2,11 +2,11 @@ import openai
2
  import gradio as gr
3
 
4
  model_id = "gpt-3.5-turbo"
 
5
 
6
  # Getting responses using the OpenAI API
7
  def answer_chatgpt(api_key, message, history, conversation):
8
  history = history or []
9
- conversation = conversation or []
10
  prompt = f"{message}"
11
  conversation.append({"role": "user", "content": f"{prompt}"})
12
  # OPENAI API KEY
@@ -20,6 +20,11 @@ def answer_chatgpt(api_key, message, history, conversation):
20
  history.append((message, answer))
21
  conversation.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
22
  return history, history
 
 
 
 
 
23
 
24
  # User input
25
  block = gr.Blocks()
@@ -32,8 +37,9 @@ with block:
32
  chatbot = gr.Chatbot()
33
  message = gr.Textbox(placeholder="message")
34
  state = gr.State()
35
- memories = gr.State()
36
  submit = gr.Button("Send")
37
- submit.click(answer_chatgpt, inputs=[api_key, message, state, memories], outputs=[chatbot, state])
 
 
38
 
39
  block.launch(debug=True)
 
2
  import gradio as gr
3
 
4
  model_id = "gpt-3.5-turbo"
5
+ conversation = []
6
 
7
  # Getting responses using the OpenAI API
8
  def answer_chatgpt(api_key, message, history, conversation):
9
  history = history or []
 
10
  prompt = f"{message}"
11
  conversation.append({"role": "user", "content": f"{prompt}"})
12
  # OPENAI API KEY
 
20
  history.append((message, answer))
21
  conversation.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
22
  return history, history
23
+
24
+
25
+ def Clean(history, conversation):
26
+ history = []
27
+ conversation = []
28
 
29
  # User input
30
  block = gr.Blocks()
 
37
  chatbot = gr.Chatbot()
38
  message = gr.Textbox(placeholder="message")
39
  state = gr.State()
 
40
  submit = gr.Button("Send")
41
+ submit.click(answer_chatgpt, inputs=[api_key, message, state], outputs=[chatbot, state])
42
+ clean = gr.Button("Clean")
43
+ clean.click(Clean, inputs=[state])
44
 
45
  block.launch(debug=True)