# coding: utf-8 # Copyright (C) 2022, [Breezedeus](https://github.com/breezedeus). from PIL import Image, ImageFilter import streamlit as st from cnocr import CnOcr from cnocr.utils import set_logger from antiocr.anti_ocr import AntiOcr from antiocr.consts import RESOURCE_PATH logger = set_logger() st.set_page_config(layout="wide") FONT_FP = '/System/Library/Fonts/PingFang.ttc' @st.cache(allow_output_mutation=True) def get_ocr_model(): return CnOcr() def main(): st.sidebar.header('输出设置') char_reverse_ratio = st.sidebar.slider( '文字倒转概率', min_value=0.0, max_value=1.0, value=0.1 ) char_to_pinyin_ratio = st.sidebar.slider( '文字转拼音概率', min_value=0.0, max_value=1.0, value=0.1 ) cols = st.sidebar.columns(2) min_font_size = int(cols[0].number_input('最小文字大小', 2, 80, value=15)) max_font_size = int( cols[1].number_input( '最大文字大小', min_font_size + 1, 120, value=max(40, min_font_size + 1) ) ) text_color = st.sidebar.color_picker('文字颜色', value='#5087DC') st.sidebar.markdown('----') use_random_bg = st.sidebar.checkbox('随机生成背景图片') if use_random_bg: bg_text_density = st.sidebar.slider( '背景图片文字密度', min_value=0.0, max_value=3.0, value=1.0 ) cols = st.sidebar.columns(2) bg_min_size = int( cols[0].number_input('背景图片最小文字', 2, 80, key='bg_min', value=15) ) bg_max_size = int( cols[1].number_input( '背景图片最大文字', bg_min_size + 1, 120, key='bg_max', value=max(70, bg_min_size + 1), ) ) bg_text_color = st.sidebar.color_picker('背景图片文字颜色', value='#07BCE0') bg_gen_config = dict( text_density=bg_text_density, text_color=bg_text_color, min_font_size=bg_min_size, max_font_size=bg_max_size, ) bg_image = None else: bg_gen_config = None bg_image = Image.open(RESOURCE_PATH / 'bg.jpeg') bg_image = bg_image.filter(ImageFilter.MaxFilter(3)) title = '让文字自由传播:antiOCR' st.markdown(f"