nxphi47 commited on
Commit
7bd95a7
1 Parent(s): 3148f33

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -84,6 +84,10 @@ KEYWORDS = os.environ.get("KEYWORDS", "").strip()
84
  KEYWORDS = KEYWORDS.split(";") if len(KEYWORDS) > 0 else []
85
  KEYWORDS = [x.lower() for x in KEYWORDS]
86
 
 
 
 
 
87
  # gradio config
88
  PORT = int(os.environ.get("PORT", "7860"))
89
  # how many iterations to yield response
@@ -795,7 +799,8 @@ def chat_response_stream_multiturn(
795
  frequency_penalty: float,
796
  presence_penalty: float,
797
  current_time: Optional[float] = None,
798
- system_prompt: Optional[str] = SYSTEM_PROMPT_1
 
799
  ) -> str:
800
  global LOG_FILE, LOG_PATH
801
  if DEBUG:
@@ -810,6 +815,8 @@ def chat_response_stream_multiturn(
810
  global llm, RES_PRINTED
811
  assert llm is not None
812
  assert system_prompt.strip() != '', f'system prompt is empty'
 
 
813
  tokenizer = llm.get_tokenizer()
814
  # force removing all
815
  vllm_abort(llm)
@@ -829,7 +836,7 @@ def chat_response_stream_multiturn(
829
  raise gr.Error("The message cannot be empty!")
830
 
831
  message_safety = safety_check(message, history=history)
832
- if message_safety is not None:
833
  # yield message_safety
834
  raise gr.Error(message_safety)
835
 
@@ -857,7 +864,7 @@ def chat_response_stream_multiturn(
857
  # optionally check safety, and respond
858
  if STREAM_CHECK_MULTIPLE > 0 and j % STREAM_CHECK_MULTIPLE == 0:
859
  message_safety = safety_check(cur_out, history=None)
860
- if message_safety is not None:
861
  yield message_safety
862
  return
863
 
@@ -883,7 +890,7 @@ def chat_response_stream_multiturn(
883
  yield cur_out
884
 
885
  message_safety = safety_check(cur_out, history=None)
886
- if message_safety is not None:
887
  yield message_safety
888
  return
889
 
@@ -1595,6 +1602,8 @@ def launch_demo():
1595
  if ENABLE_AGREE_POPUP:
1596
  demo.load(None, None, None, _js=AGREE_POP_SCRIPTS)
1597
 
 
 
1598
  demo.queue(api_open=False)
1599
  return demo
1600
 
 
84
  KEYWORDS = KEYWORDS.split(";") if len(KEYWORDS) > 0 else []
85
  KEYWORDS = [x.lower() for x in KEYWORDS]
86
 
87
+ # bypass
88
+ BYPASS_USERS = os.environ.get("BYPASS_USERS", "").strip()
89
+ BYPASS_USERS = BYPASS_USERS.split(";") if len(BYPASS_USERS) > 0 else []
90
+
91
  # gradio config
92
  PORT = int(os.environ.get("PORT", "7860"))
93
  # how many iterations to yield response
 
799
  frequency_penalty: float,
800
  presence_penalty: float,
801
  current_time: Optional[float] = None,
802
+ system_prompt: Optional[str] = SYSTEM_PROMPT_1,
803
+ profile: Optional[gr.OAuthProfile] = None,
804
  ) -> str:
805
  global LOG_FILE, LOG_PATH
806
  if DEBUG:
 
815
  global llm, RES_PRINTED
816
  assert llm is not None
817
  assert system_prompt.strip() != '', f'system prompt is empty'
818
+ is_by_pass = False if profile is None else profile.username in BYPASS_USERS
819
+
820
  tokenizer = llm.get_tokenizer()
821
  # force removing all
822
  vllm_abort(llm)
 
836
  raise gr.Error("The message cannot be empty!")
837
 
838
  message_safety = safety_check(message, history=history)
839
+ if message_safety is not None and not is_by_pass:
840
  # yield message_safety
841
  raise gr.Error(message_safety)
842
 
 
864
  # optionally check safety, and respond
865
  if STREAM_CHECK_MULTIPLE > 0 and j % STREAM_CHECK_MULTIPLE == 0:
866
  message_safety = safety_check(cur_out, history=None)
867
+ if message_safety is not None and not is_by_pass:
868
  yield message_safety
869
  return
870
 
 
890
  yield cur_out
891
 
892
  message_safety = safety_check(cur_out, history=None)
893
+ if message_safety is not None and not is_by_pass:
894
  yield message_safety
895
  return
896
 
 
1602
  if ENABLE_AGREE_POPUP:
1603
  demo.load(None, None, None, _js=AGREE_POP_SCRIPTS)
1604
 
1605
+ login_btn = gr.LoginButton()
1606
+
1607
  demo.queue(api_open=False)
1608
  return demo
1609