|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from functools import lru_cache |
|
from aip import AipImageCensor, AipOcr |
|
|
|
_ = """ |
|
31294942 |
|
d8pnIpxUaZ7ce65StreDuOY0 |
|
lldWlW574LV8n3mIG2xQvcL6Wa7MXi5q |
|
""".strip().split() |
|
ai = AipImageCensor(*_) |
|
|
|
@lru_cache() |
|
def text_censor(text='一群垃圾去找小姐'): |
|
data = ai.textCensorUserDefined(text).get('data', []) |
|
rst = [] |
|
for _ in data: |
|
d = {} |
|
d['msg'] = _['msg'] |
|
hits = _['hits'] |
|
d['words'] = sum([hit['words'] for hit in hits], []) |
|
rst.append(d) |
|
return rst if rst else ['合规'] |
|
|
|
@lru_cache() |
|
def image_censor(img): |
|
data = ai.imageCensorUserDefined(img).get('data', []) |
|
rst = [] |
|
for _ in data: |
|
d = {} |
|
d['msg'] = _['msg'] |
|
|
|
|
|
rst.append(d) |
|
return rst if rst else ['合规'] |
|
|
|
import streamlit as st |
|
|
|
tab1, tab2, tab3 = st.tabs(["文本审核", "图片审核", "视频审核"]) |
|
|
|
with tab1: |
|
st.header("文本审核") |
|
text= st.text_input('请输入文本', value='一群垃圾去找小姐') |
|
button = st.button('开始审核文本') |
|
if button: |
|
st.json(text_censor(text)) |
|
|
|
with tab2: |
|
st.header("图像审核") |
|
file = st.file_uploader('请上传图片') |
|
button = st.button('开始审核图片') |
|
|
|
if file and button: |
|
col1, col2 = st.columns(2) |
|
with col1: |
|
st.image(file) |
|
with col2: |
|
st.json(image_censor(file.read())) |
|
|
|
|
|
|
|
with tab3: |
|
st.header("视频审核") |
|
|