gerasdf commited on
Commit
3491ea6
·
1 Parent(s): 7ec8702

factored out common auth code

Browse files
Files changed (1) hide show
  1. query.py +9 -4
query.py CHANGED
@@ -118,9 +118,15 @@ AUTH_JS = """function auth_js(token, state) {
118
  }
119
  """
120
 
121
- def chat(message, history, state):
122
- if (state is None) or (not state['user']):
 
123
  gr.Warning("You need to authenticate first")
 
 
 
 
 
124
  yield "You need to authenticate first"
125
  elif AI:
126
  if not history:
@@ -144,8 +150,7 @@ def chat(message, history, state):
144
  yield f"{time.ctime()}: You said: {message}"
145
 
146
  def on_audio(path, state):
147
- if (state is None) or (not state['user']):
148
- gr.Warning("You need to authenticate first")
149
  return (gr.update(), None)
150
  else:
151
  if not path:
 
118
  }
119
  """
120
 
121
+ def not_authenticated(state):
122
+ answer = (state is None) or (not state['user'])
123
+ if answer:
124
  gr.Warning("You need to authenticate first")
125
+ return answer
126
+
127
+
128
+ def chat(message, history, state):
129
+ if not_authenticated(state):
130
  yield "You need to authenticate first"
131
  elif AI:
132
  if not history:
 
150
  yield f"{time.ctime()}: You said: {message}"
151
 
152
  def on_audio(path, state):
153
+ if not_authenticated(state):
 
154
  return (gr.update(), None)
155
  else:
156
  if not path: