File size: 2,064 Bytes
60b9491 5120739 60b9491 ac2870e 60b9491 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import gradio as gr
from transformers import pipeline
auth_token = os.environ.get("access_token")
pipeline_en = pipeline(task="text-classification", model="Hello-SimpleAI/chatgpt-qa-detector-distil",use_auth_token=auth_token)
# pipeline_en = pipeline_zh
# pipeline_zh = pipeline(task="text2text-generation", model="beyond/genius-base-chinese")
def predict_en(q,a):
res = pipeline_en({"text":q, "text_pair":a})
return res['label'],res['score']
def predict_zh(sketch):
# generated_text = pipeline_zh(sketch, num_beams=3, do_sample=True, max_length=200)[0]['generated_text']
# return generated_text.replace(' ','')
return ''
with gr.Blocks() as demo:
gr.Markdown("""
## ChatGPT detector
""")
with gr.Tab("English"):
q1 = gr.Textbox(lines=2, label='Question',value="What stops a restaurant from noting down my credit card info and using it ? No offense to restaurants . Can be generalized to anyone who I give my credit card info to . Explain like I'm five.")
a1 = gr.Textbox(lines=5, label='Answer',value="There are a few things that can help protect your credit card information from being misused when you give it to a restaurant or any other business:\n\nEncryption: Many businesses use encryption to protect your credit card information when it is being transmitted or stored. This means that the information is transformed into a code that is difficult for anyone to read without the right key.")
label = gr.Textbox(lines=1, label='Predicted Label 🎃')
score = gr.Textbox(lines=1, label='Prob')
button1 = gr.Button("🤖 Predict!")
# with gr.Tab("Chinese"):
# input2 = gr.Textbox(lines=5, value="")
# output2 = gr.Textbox(lines=5)
# output2 = output2
# button2 = gr.Button("Generate")
# with gr.Accordion("Open for More!"):
# gr.Markdown("Look at me...")
button1.click(predict_en, inputs=[q1,a1], outputs=[label,score])
# button2.click(predict_zh, inputs=input2, outputs=output2)
demo.launch() |