| import gradio as gr | |
| import requests | |
| def audit_text(text, url): | |
| data = { | |
| "text": text, | |
| "source": "ALIYUN", | |
| "model": "ALIYUN_TEXT_AUDIT" | |
| } | |
| res = requests.post(url, json=data) | |
| data = res.json() | |
| is_pass = data.get('data', {}).get('pass') | |
| if is_pass: | |
| return data, f'合规' | |
| return data, '不合规' | |
| def audit_tab(): | |
| with gr.Tab("关键词审核"): | |
| with gr.Column(): | |
| url_input = gr.Textbox(label='接口链接') | |
| text_input = gr.Textbox(label="待审核的关键词", lines=10) | |
| gr.Examples(['你是傻逼吧', '你是天才'], inputs=text_input) | |
| with gr.Row(): | |
| text_output = gr.Json(label="结果", lines=10) | |
| label_output = gr.Label() | |
| text_button = gr.Button('检测') | |
| text_button.click(audit_text, inputs=[text_input, url_input], outputs=[text_output, label_output]) | |