Caerii commited on
Commit
aab6523
·
1 Parent(s): 5190e3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -29,23 +29,27 @@ def openai_chatbot(message, history=None):
29
  user=None
30
  )
31
 
32
- return response.choices[0].text.strip()
 
 
 
33
  except Exception as e:
34
  print(f"An error occurred: {e}")
35
- return "Sorry, there was an error processing your request."
36
 
37
  chat_interface = gr.Interface(
38
  fn=openai_chatbot,
39
  inputs=[
40
- gr.Textbox(label="Your Message"), # Updated to gr.Textbox
41
- gr.State() # State remains the same
 
 
 
 
42
  ],
43
- outputs=[gr.Textbox(label="OpenAI Response")], # Updated to gr.Textbox
44
  title="OpenAI Chatbot",
45
  description="Talk to a bot powered by OpenAI GPT-3."
46
  )
47
 
48
-
49
-
50
  if __name__ == "__main__":
51
  chat_interface.launch(debug=True)
 
29
  user=None
30
  )
31
 
32
+ new_history = history if history else []
33
+ new_history.append((message, response.choices[0].text.strip()))
34
+
35
+ return response.choices[0].text.strip(), new_history # Return both response and updated history
36
  except Exception as e:
37
  print(f"An error occurred: {e}")
38
+ return "Sorry, there was an error processing your request.", history # Include history in error case too
39
 
40
  chat_interface = gr.Interface(
41
  fn=openai_chatbot,
42
  inputs=[
43
+ gr.Textbox(label="Your Message"),
44
+ gr.State() # State input
45
+ ],
46
+ outputs=[
47
+ gr.Textbox(label="OpenAI Response"),
48
+ gr.State() # Corresponding State output
49
  ],
 
50
  title="OpenAI Chatbot",
51
  description="Talk to a bot powered by OpenAI GPT-3."
52
  )
53
 
 
 
54
  if __name__ == "__main__":
55
  chat_interface.launch(debug=True)