Sanmath commited on
Commit
b7ce9d2
·
verified ·
1 Parent(s): d5e36bf

Upload app (2).py

Browse files
Files changed (1) hide show
  1. app (2).py +63 -0
app (2).py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import math
3
+ import gradio as gr
4
+
5
+ EN_US = os.getenv("LANG") != "zh_CN.UTF-8"
6
+
7
+ ZH2EN = {
8
+ "待分割字符串": "String to be split",
9
+ "分割步长": "Split step",
10
+ "状态栏": "Status",
11
+ "分割结果": "Split result",
12
+ "字符串分割": "String Splitter",
13
+ }
14
+
15
+
16
+ def _L(zh_txt: str):
17
+ return ZH2EN[zh_txt] if EN_US else zh_txt
18
+
19
+
20
+ def infer(cookie: str, step: int):
21
+ status = "Success"
22
+ output = ""
23
+ try:
24
+ cookie = cookie.strip()
25
+ if not cookie:
26
+ raise ValueError("请输入 cookie !")
27
+
28
+ md_lines = []
29
+ size = len(cookie)
30
+ count = math.ceil(size / step)
31
+ for i in range(count):
32
+ md_lines.append(
33
+ f"```txt\n{cookie[i * step: min((i + 1) * step, size)]}\n```")
34
+
35
+ output = "\n".join(md_lines)
36
+
37
+ except Exception as e:
38
+ status = f"{e}"
39
+
40
+ return status, output
41
+
42
+
43
+ if __name__ == "__main__":
44
+ gr.Interface(
45
+ fn=infer,
46
+ inputs=[
47
+ gr.TextArea(label=_L("待分割字符串")),
48
+ gr.Slider(
49
+ label=_L("分割步长"),
50
+ minimum=1,
51
+ maximum=255959,
52
+ step=1,
53
+ value=1024,
54
+ ),
55
+ ],
56
+ outputs=[
57
+ gr.Textbox(label=_L("状态栏"), show_copy_button=True),
58
+ gr.Markdown(label=_L("分割结果"), container=True,
59
+ show_copy_button=True),
60
+ ],
61
+ flagging_mode="never",
62
+ title=_L("字符串分割")
63
+ ).launch()