qmaruf commited on
Commit
6ac4e6b
·
1 Parent(s): 35e7b6a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. aussie_bot.py +19 -7
aussie_bot.py CHANGED
@@ -59,18 +59,30 @@ def interface() -> None:
59
  chatbot = gr.Chatbot()
60
  msg = gr.Textbox()
61
  clear = gr.Button('Clear')
62
- chatgpt_chain = get_chain()
 
 
 
 
 
63
 
64
  def user(user_message, history):
65
  return '', history + [[user_message, None]]
66
 
67
  def bot(history):
68
- human_input = history[-1][0]
69
-
70
- if len(human_input) < 512:
71
- response = chatgpt_chain.predict(human_input=human_input)
72
- else:
73
- response = 'Sorry, I can only answer questions shorter than 512 characters.'
 
 
 
 
 
 
 
74
 
75
  history[-1][1] = ''
76
  for character in response:
 
59
  chatbot = gr.Chatbot()
60
  msg = gr.Textbox()
61
  clear = gr.Button('Clear')
62
+
63
+ try:
64
+ chatgpt_chain = get_chain()
65
+ except Exception as e:
66
+ print(e)
67
+ chatgpt_chain = None
68
 
69
  def user(user_message, history):
70
  return '', history + [[user_message, None]]
71
 
72
  def bot(history):
73
+ try:
74
+ human_input = history[-1][0]
75
+
76
+ if chatgpt_chain is None:
77
+ raise Exception('Chatbot not initialized')
78
+
79
+ if len(human_input) < 512:
80
+ response = chatgpt_chain.predict(human_input=human_input)
81
+ else:
82
+ response = 'Sorry, I can only answer questions shorter than 512 characters.'
83
+ except Exception as e:
84
+ print(e)
85
+ response = 'Sorry, I had trouble answering that question. Please try again.'
86
 
87
  history[-1][1] = ''
88
  for character in response: