zxw commited on
Commit
fef638f
1 Parent(s): b1131e0
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -149,19 +149,24 @@ def inference_gen(text, task, do_sample, top_p, top_k, max_token, temperature, b
149
  #print(generate_config)
150
  #print(text)
151
  default_example = default_example and generate_config == default_generate_config
152
- try:
153
- if default_example:
154
- prediction = cl.generate(
155
- model_name='clueai-base',
156
- prompt=text)
157
- else:
158
- prediction = cl.generate(
159
- model_name='clueai-base',
160
- prompt=text,
161
- generate_config=generate_config)
162
- except Exception as e:
163
- logger.error(f"error, {e}")
164
- return
 
 
 
 
 
165
 
166
  return prediction.generations[0].text
167
 
 
149
  #print(generate_config)
150
  #print(text)
151
  default_example = default_example and generate_config == default_generate_config
152
+ try_num = 3
153
+ while try_num:
154
+ try:
155
+ if default_example:
156
+ prediction = cl.generate(
157
+ model_name='clueai-base',
158
+ prompt=text)
159
+ else:
160
+ prediction = cl.generate(
161
+ model_name='clueai-base',
162
+ prompt=text,
163
+ generate_config=generate_config)
164
+ except Exception as e:
165
+ logger.error(f"error, {e}")
166
+ return
167
+ if prediction.generations[0].text != "含有违规词,不予展示":
168
+ break
169
+ try_num -= 1
170
 
171
  return prediction.generations[0].text
172