File size: 1,827 Bytes
b966bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Project      : Python.
# @File         : 8_内容审核
# @Time         : 2023/3/15 上午10:40
# @Author       : yuanjie
# @WeChat       : meutils
# @Software     : PyCharm
# @Description  : pip install baidu-aip




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): # open('hao123 logo.png', 'rb').read()
    data = ai.imageCensorUserDefined(img).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 ['合规']

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("视频审核")