KuangDW commited on
Commit
6d30719
·
1 Parent(s): 03c399b

fix session state

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -91,11 +91,12 @@ def check_token_length(text, max_tokens=1024):
91
 
92
  import uuid
93
  def get_user_session(state):
 
 
94
  if not state.get("session_id"):
95
  state["session_id"] = uuid.uuid4().hex
96
  return state["session_id"]
97
 
98
-
99
  # ---------- Translation Function ----------
100
 
101
  def mpc_initial_translate(source_sentence, src_language, tgt_language):
@@ -210,6 +211,8 @@ def mpc_translation(text, src_language, target_language, iterations, session_id)
210
 
211
  def process_text(text, src_language, target_language, max_iterations_value, threshold_value,
212
  good_ref_contexts_num_value, translation_methods, state):
 
 
213
  session_id = get_user_session(state)
214
 
215
  """
 
91
 
92
  import uuid
93
  def get_user_session(state):
94
+ if not state:
95
+ state = {}
96
  if not state.get("session_id"):
97
  state["session_id"] = uuid.uuid4().hex
98
  return state["session_id"]
99
 
 
100
  # ---------- Translation Function ----------
101
 
102
  def mpc_initial_translate(source_sentence, src_language, tgt_language):
 
211
 
212
  def process_text(text, src_language, target_language, max_iterations_value, threshold_value,
213
  good_ref_contexts_num_value, translation_methods, state):
214
+
215
+ state = state or {}
216
  session_id = get_user_session(state)
217
 
218
  """