File size: 601 Bytes
dc444e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import gradio as gr
import re

def count_characters(input_str):
    # 去除空格和标点符号
    filtered_str = re.sub(r'\s+|[^\w\s]', '', input_str)
    char_count = len(filtered_str)
    return f"该文本共有 {char_count} 个字符(不包含空格和标点)"

def main():
    interface = gr.Interface(
        fn=count_characters, 
        inputs=gr.Textbox(label="输入文本"), 
        outputs="text",
        title="字数检查工具",
        description="输入文本,统计不包含空格和标点的字数"
    )
    interface.launch()

if __name__ == '__main__':
    main()