celestialli commited on
Commit
05d618f
·
1 Parent(s): 89634f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -11,6 +11,7 @@ from websocket import WebSocketConnectionClosedException
11
  import gradio as gr
12
  import requests
13
  import logging
 
14
 
15
  from fastchat.conversation import SeparatorStyle
16
  from fastchat.constants import (
@@ -50,6 +51,15 @@ no_change_btn = gr.Button.update()
50
  enable_btn = gr.Button.update(interactive=True)
51
  disable_btn = gr.Button.update(interactive=False)
52
 
 
 
 
 
 
 
 
 
 
53
  enable_moderation = True if os.environ.get('enable_moderation', default='False')=="True" else False
54
  concurrency_count = int(os.environ.get('concurrency_count', default='10'))
55
  model_list_mode = os.environ.get('model_list_mode', default='reload')
@@ -69,10 +79,6 @@ dataset_sample = {
69
  "train": ["abcdef"],
70
  "valid": ["zxcvbn"]
71
  },
72
- "cat": {
73
- "train": ["aaaaaa"],
74
- "valid": ["bbbbbb"]
75
- }
76
  }
77
 
78
 
@@ -99,6 +105,8 @@ ip_expiration_dict = defaultdict(lambda: 0)
99
  def is_legal_char(c):
100
  if c.isalnum():
101
  return True
 
 
102
  if c in "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏.":
103
  return True
104
  if c in '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~':
@@ -384,6 +392,9 @@ def bot_response(state, temperature, top_p, max_new_tokens, request: gr.Request)
384
  try:
385
  for data in stream_iter:
386
  if data["error_code"] == 0:
 
 
 
387
  output = data["text"].strip()
388
  if "vicuna" in model_name:
389
  output = post_process_code(output)
@@ -760,7 +771,10 @@ def build_demo(models):
760
 
761
  return demo
762
 
763
-
 
 
 
764
  models = get_model_list(midware_url)
765
 
766
  # Launch the demo
 
11
  import gradio as gr
12
  import requests
13
  import logging
14
+ import re
15
 
16
  from fastchat.conversation import SeparatorStyle
17
  from fastchat.constants import (
 
51
  enable_btn = gr.Button.update(interactive=True)
52
  disable_btn = gr.Button.update(interactive=False)
53
 
54
+
55
+ def get_internet_ip():
56
+ r = requests.get("http://txt.go.sohu.com/ip/soip")
57
+ ip = re.findall(r'\d+.\d+.\d+.\d+', r.text)
58
+ if ip is not None and len(ip) > 0:
59
+ return ip[0]
60
+ return None
61
+
62
+
63
  enable_moderation = True if os.environ.get('enable_moderation', default='False')=="True" else False
64
  concurrency_count = int(os.environ.get('concurrency_count', default='10'))
65
  model_list_mode = os.environ.get('model_list_mode', default='reload')
 
79
  "train": ["abcdef"],
80
  "valid": ["zxcvbn"]
81
  },
 
 
 
 
82
  }
83
 
84
 
 
105
  def is_legal_char(c):
106
  if c.isalnum():
107
  return True
108
+ if '\u4e00' <= c <= '\u9fff':
109
+ return True
110
  if c in "!?。"#$%&'()*+,-/:;<=>@[\]^_`{|}~⦅⦆「」、、〃》「」『』【】〔〕〖〗〘〙〚〛〜〝〞〟〰〾〿–—‘’‛“”„‟…‧﹏.":
111
  return True
112
  if c in '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~':
 
392
  try:
393
  for data in stream_iter:
394
  if data["error_code"] == 0:
395
+ finish_reason = data.get("finish_reason", None)
396
+ if finish_reason is not None and finish_reason == "length":
397
+ gr.Warning("Answer interrupted because the setting of [Max output tokens], try set a larger value.")
398
  output = data["text"].strip()
399
  if "vicuna" in model_name:
400
  output = post_process_code(output)
 
771
 
772
  return demo
773
 
774
+ try:
775
+ print("Internet IP:", get_internet_ip())
776
+ except Exception as e:
777
+ print(f"Get Internet IP error: {e}")
778
  models = get_model_list(midware_url)
779
 
780
  # Launch the demo