Upload main.py
Browse files
main.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import re
|
3 |
+
|
4 |
+
def count_characters(input_str):
|
5 |
+
# 去除空格和标点符号
|
6 |
+
filtered_str = re.sub(r'\s+|[^\w\s]', '', input_str)
|
7 |
+
char_count = len(filtered_str)
|
8 |
+
return f"该文本共有 {char_count} 个字符(不包含空格和标点)"
|
9 |
+
|
10 |
+
def main():
|
11 |
+
interface = gr.Interface(
|
12 |
+
fn=count_characters,
|
13 |
+
inputs=gr.Textbox(label="输入文本"),
|
14 |
+
outputs="text",
|
15 |
+
title="字数检查工具",
|
16 |
+
description="输入文本,统计不包含空格和标点的字数"
|
17 |
+
)
|
18 |
+
interface.launch()
|
19 |
+
|
20 |
+
if __name__ == '__main__':
|
21 |
+
main()
|