ssocean commited on
Commit
fb9334a
·
verified ·
1 Parent(s): 23551ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -15,6 +15,8 @@ tokenizer = None
15
 
16
  @spaces.GPU(duration=60, enable_queue=True)
17
  def predict(title, abstract):
 
 
18
  global model, tokenizer
19
  if model is None:
20
  model = AutoModelForSequenceClassification.from_pretrained(
@@ -86,13 +88,10 @@ examples = [
86
  ]
87
 
88
  def validate_input(title, abstract):
89
- """验证输入是否符合要求"""
90
-
91
- # 黑名单:屏蔽非拉丁字符
92
  non_latin_pattern = re.compile(r'[^\u0000-\u007F]')
93
- if len(title.split(' '))<4:
94
  return False, "The title must be at least 3 words long."
95
- if len(abstract.split(' ')) < 50:
96
  return False, "The abstract must be at least 50 words long."
97
  if len((title + abstract).split(' '))>1024:
98
  return True, "Warning, The input length is approaching tokenization limits (1024) and may be truncated without further warning!"
@@ -104,7 +103,7 @@ def validate_input(title, abstract):
104
  return True, "Inputs are valid! Good to go!"
105
 
106
  def update_button_status(title, abstract):
107
- """根据输入内容动态更新按钮状态"""
108
  valid, message = validate_input(title, abstract)
109
  if not valid:
110
  return gr.update(value="Error: " + message), gr.update(interactive=False)
@@ -116,6 +115,7 @@ with gr.Blocks() as iface:
116
  # 🧠 Predict Academic Impact of Newly Published Paper!
117
  ### Estimate the future academic impact of a paper using LLM
118
  [Read the full paper](https://arxiv.org/abs/2408.03934)
 
119
  """)
120
  with gr.Row():
121
  with gr.Column():
 
15
 
16
  @spaces.GPU(duration=60, enable_queue=True)
17
  def predict(title, abstract):
18
+ title = title.replace("\n", " ").strip()
19
+ abstract = abstract.replace("\n", " ").strip()
20
  global model, tokenizer
21
  if model is None:
22
  model = AutoModelForSequenceClassification.from_pretrained(
 
88
  ]
89
 
90
  def validate_input(title, abstract):
 
 
 
91
  non_latin_pattern = re.compile(r'[^\u0000-\u007F]')
92
+ if len(title.strip().split(' '))<3:
93
  return False, "The title must be at least 3 words long."
94
+ if len(abstract.strip().split(' ')) < 50:
95
  return False, "The abstract must be at least 50 words long."
96
  if len((title + abstract).split(' '))>1024:
97
  return True, "Warning, The input length is approaching tokenization limits (1024) and may be truncated without further warning!"
 
103
  return True, "Inputs are valid! Good to go!"
104
 
105
  def update_button_status(title, abstract):
106
+
107
  valid, message = validate_input(title, abstract)
108
  if not valid:
109
  return gr.update(value="Error: " + message), gr.update(interactive=False)
 
115
  # 🧠 Predict Academic Impact of Newly Published Paper!
116
  ### Estimate the future academic impact of a paper using LLM
117
  [Read the full paper](https://arxiv.org/abs/2408.03934)
118
+ Please note that due to the characteristics of ZeroGPU, quantized models cannot be preloaded. Each time you click "Predict," the model will need to be reinitialized, which may take additional time (usually less than 20s).
119
  """)
120
  with gr.Row():
121
  with gr.Column():