JiachenFu's picture
update: app
6600152
input_text,output,timestamp
"'def greet(input_text):
sub_texts = text_splitter.split_text(input_text) # 修改为split_text获取文本列表
html_output = []
for sub_text in sub_texts:
tokenized = scoring_tokenizer(sub_text, truncation=True, return_tensors=""pt"", padding=True, return_token_type_ids=False).to(device)
labels = tokenized.input_ids[:, 1:]
with torch.no_grad():
logits_score = scoring_model(**tokenized).logits[:, :-1]
logits_ref = logits_score
crit, _ = criterion_fn(logits_ref, logits_score, labels)
crit = crit.cpu().numpy().item()
prob = prob_estimator.crit_to_prob(crit)
# 根据概率值设置颜色
if prob >= 0.7:
color = ""red""
elif prob >= 0.3:
color = ""orange""
else:
color = ""white""
# 创建带样式的HTML内容
html_output.append(f'<span style=""color: {color};"">{sub_text} (Probability: {prob:.2f})</span>')
# 用换行连接所有结果
return ""<br>"".join(html_output)
demo = gr.Interface(
fn=greet,
inputs=[""text""],
outputs=gr.HTML() # 修改为HTML输出组件
)","'<span style=""color: white;"">def greet(input_text):
sub_texts = text_splitter.split_text(input_text) # 修改为split_text获取文本列表
html_output = []
for (Probability: 0.09)</span><br><span style=""color: white;"">sub_text in sub_texts:
tokenized = scoring_tokenizer(sub_text, truncation=True, return_tensors=""pt"", padding=True, retur (Probability: 0.03)</span><br><span style=""color: white;"">n_token_type_ids=False).to(device)
labels = tokenized.input_ids[:, 1:]
with torch.no_grad():
logits_ (Probability: 0.05)</span><br><span style=""color: white;"">score = scoring_model(**tokenized).logits[:, :-1]
logits_ref = logits_score
crit, _ = criterion_fn(logit (Probability: 0.00)</span><br><span style=""color: white;"">s_ref, logits_score, labels)
crit = crit.cpu().numpy().item()
prob = prob_estimator.crit_to_prob(crit) (Probability: 0.02)</span><br><span style=""color: white;""># 根据概率值设置颜色
if prob >= 0.7:
color = ""red""
elif prob >= 0.3:
color = ""or (Probability: 0.09)</span><br><span style=""color: white;"">ange""
else:
color = ""white""
# 创建带样式的HTML内容
html_output.append(f'<span style=""color: (Probability: 0.19)</span><br><span style=""color: white;"">{color};"">{sub_text} (Probability: {prob:.2f})</span>')
# 用换行连接所有结果
return ""<br>"".join(html_output)
demo = gr.Int (Probability: 0.01)</span><br><span style=""color: white;"">erface(
fn=greet,
inputs=[""text""],
outputs=gr.HTML() # 修改为HTML输出组件
) (Probability: 0.06)</span>",2025-01-30 11:44:36.020197