import os import gradio as gr from transformers import pipeline from huggingface_hub import login auth_token = os.environ.get("access_token") login(token=auth_token) pipeline_en = pipeline(task="text-classification", model="MeiJuice/CheckGPT") pipeline_zh = pipeline(task="text-classification", model="MeiJuice/CheckGPT-Chinese") def predict_en(text): res = pipeline_en(text, truncation=True)[0] return "ChatGPT" if res['label'] == "LABEL_1" else "human", res['score'] def predict_zh(text): res = pipeline_zh(text, truncation=True, max_length=512)[0] return "ChatGPT" if res['label'] == "LABEL_1" else "human", res['score'] with gr.Blocks() as demo: with gr.Tab("English"): gr.Markdown(""" Note: Providing more text to the `Text` box can make the prediction more accurate! """) t1 = gr.Textbox(lines=5, label='Text', value="No one can call back yesterday, Yesterday will not be called again.") button1 = gr.Button("Predict!") label1 = gr.Textbox(lines=1, label='Predicted Label') score1 = gr.Textbox(lines=1, label='Prob') with gr.Tab("中文版"): gr.Markdown(""" 注意: 在`文本`栏中输入更多的文本,可以让预测更准确哦! """) t2 = gr.Textbox(lines=5, label='文本', value="联邦学习(Federated learning)是在进行分布式机器学习的过程中,各参与方可借助其他参与方数据进行联合建模和使用模型。参与各方无需传递和共享原始数据资源,同时保护模型参数,即在数据不出本地的情况下,进行数据联合训练、联合应用,建立合法合规的机器学习模型,成为一种解决合作中数据隐私与数据共享矛盾的新路径,FL本质上承诺多方通过交换梯度而不是原始数据来联合训练模型。") button2 = gr.Button("预测!") label2 = gr.Textbox(lines=1, label='预测结果 ') score2 = gr.Textbox(lines=1, label='模型概率') button1.click(predict_en, inputs=[t1], outputs=[label1, score1], api_name='predict_en') button2.click(predict_zh, inputs=[t2], outputs=[label2, score2], api_name='predict_zh') gr.Markdown("""
""") demo.launch()