betterme commited on
Commit
b966bc9
1 Parent(s): d38579a
Files changed (49) hide show
  1. .streamlit/_config.toml +186 -0
  2. .streamlit/config.toml +26 -0
  3. Dockerfile +23 -0
  4. README.md +2 -1
  5. _👋_.py +9 -0
  6. git_init.sh +9 -0
  7. packages.txt +0 -0
  8. pages/0_留言板.py +18 -0
  9. pages/1000_文本标识.py +38 -0
  10. pages/1001_多选组件.py +51 -0
  11. pages/1002_pandas_profiling.py +21 -0
  12. pages/1003_streamlit_authenticator.py +92 -0
  13. pages/1004_streamlit_option_menu.py +33 -0
  14. pages/111_📚_PDF简单表格提取.py +38 -0
  15. pages/112_📚_简单的配置界面.py +27 -0
  16. pages/113_💰_穿透.py +27 -0
  17. pages/1_🔥_模型生成代码.py +56 -0
  18. pages/2_📚_PDF预览.py +53 -0
  19. pages/3_🐧_分词.py +47 -0
  20. pages/4_🤩_Apps.py +23 -0
  21. pages/5_👍_Postman.py +28 -0
  22. pages/6666_🐧_hr.py +50 -0
  23. pages/666_😝_TEST.py +69 -0
  24. pages/66_🔥_ASCII字符画.py +107 -0
  25. pages/6_🕷_coding.py +20 -0
  26. pages/7_登录.py +64 -0
  27. pages/888_🌰_demo.py +29 -0
  28. pages/889_机器监控.py +118 -0
  29. pages/8_内容审核.py +74 -0
  30. pages/990_streamlit_autorefresh.py +19 -0
  31. pages/991_streamlit_apex_charts.py +19 -0
  32. pages/992_streamlit_chat.py +25 -0
  33. pages/993_streamlit_text_rating.py +11 -0
  34. pages/994_自定义style.py +39 -0
  35. pages/995_streamlit_echarts.py +25 -0
  36. pages/996_streamlit_pyecharts.py +73 -0
  37. pages/997_streamlit_aggrid.py +24 -0
  38. pages/998_streamlit_agraph.py +49 -0
  39. pages/998_知识图谱.py +39 -0
  40. pages/999_draw_table.py +129 -0
  41. pages/__init__.py +11 -0
  42. pages/chart.py +20 -0
  43. pages/demo-aggrid-width-center.py +64 -0
  44. pages/iframe.py +36 -0
  45. pages/xxxx.py +9 -0
  46. pages/多轮对话.py +53 -0
  47. pages/弹窗.py +45 -0
  48. requirements.txt +21 -0
  49. run.sh +10 -0
.streamlit/_config.toml ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Below are all the sections and options you can have in ~/.streamlit/config.toml.
2
+
3
+ [global]
4
+
5
+ # By default, Streamlit checks if the Python watchdog module is available and, if not, prints a warning asking for you to install it. The watchdog module is not required, but highly recommended. It improves Streamlit's ability to detect changes to files in your filesystem.
6
+ # If you'd like to turn off this warning, set this to True.
7
+ # Default: false
8
+ # disableWatchdogWarning = false
9
+
10
+ # If True, will show a warning when you run a Streamlit-enabled script via "python my_script.py".
11
+ # Default: true
12
+ # showWarningOnDirectExecution = true
13
+
14
+ # DataFrame serialization.
15
+ # Acceptable values: - 'legacy': Serialize DataFrames using Streamlit's custom format. Slow but battle-tested. - 'arrow': Serialize DataFrames using Apache Arrow. Much faster and versatile.
16
+ # Default: "arrow"
17
+ # dataFrameSerialization = "arrow"
18
+
19
+
20
+ [logger]
21
+
22
+ # Level of logging: 'error', 'warning', 'info', or 'debug'.
23
+ # Default: 'info'
24
+ # level = "info"
25
+
26
+ # String format for logging messages. If logger.datetimeFormat is set, logger messages will default to `%(asctime)s.%(msecs)03d %(message)s`. See [Python's documentation](https://docs.python.org/2.6/library/logging.html#formatter-objects) for available attributes.
27
+ # Default: "%(asctime)s %(message)s"
28
+ # messageFormat = "%(asctime)s %(message)s"
29
+
30
+
31
+ [client]
32
+
33
+ # Whether to enable st.cache.
34
+ # Default: true
35
+ # caching = true
36
+
37
+ # If false, makes your Streamlit script not draw to a Streamlit app.
38
+ # Default: true
39
+ # displayEnabled = true
40
+
41
+ # Controls whether uncaught app exceptions are displayed in the browser. By default, this is set to True and Streamlit displays app exceptions and associated tracebacks in the browser.
42
+ # If set to False, an exception will result in a generic message being shown in the browser, and exceptions and tracebacks will be printed to the console only.
43
+ # Default: true
44
+ # showErrorDetails = true
45
+
46
+
47
+ [runner]
48
+
49
+ # Allows you to type a variable or string by itself in a single line of Python code to write it to the app.
50
+ # Default: true
51
+ # The value below was set in /Users/yuanjie/.streamlit/config.toml
52
+ magicEnabled = false
53
+
54
+ # Install a Python tracer to allow you to stop or pause your script at any point and introspect it. As a side-effect, this slows down your script's execution.
55
+ # Default: false
56
+ # installTracer = false
57
+
58
+ # Sets the MPLBACKEND environment variable to Agg inside Streamlit to prevent Python crashing.
59
+ # Default: true
60
+ # fixMatplotlib = true
61
+
62
+ # Run the Python Garbage Collector after each script execution. This can help avoid excess memory use in Streamlit apps, but could introduce delay in rerunning the app script for high-memory-use applications.
63
+ # Default: true
64
+ # postScriptGC = true
65
+
66
+ # Handle script rerun requests immediately, rather than waiting for script execution to reach a yield point. Enabling this will make Streamlit much more responsive to user interaction, but it can lead to race conditions in apps that mutate session_state data outside of explicit session_state assignment statements.
67
+ # Default: false
68
+ # fastReruns = false
69
+
70
+
71
+ [server]
72
+
73
+ # List of folders that should not be watched for changes. This impacts both "Run on Save" and @st.cache.
74
+ # Relative paths will be taken as relative to the current working directory.
75
+ # Example: ['/home/user1/env', 'relative/path/to/folder']
76
+ # Default: []
77
+ # folderWatchBlacklist = []
78
+
79
+ # Change the type of file watcher used by Streamlit, or turn it off completely.
80
+ # Allowed values: * "auto" : Streamlit will attempt to use the watchdog module, and falls back to polling if watchdog is not available. * "watchdog" : Force Streamlit to use the watchdog module. * "poll" : Force Streamlit to always use polling. * "none" : Streamlit will not watch files.
81
+ # Default: "auto"
82
+ # fileWatcherType = "auto"
83
+
84
+ # Symmetric key used to produce signed cookies. If deploying on multiple replicas, this should be set to the same value across all replicas to ensure they all share the same secret.
85
+ # Default: randomly generated secret key.
86
+ # cookieSecret = "fb4103b4f96550d923a2a8178482538b61aa55fd3a76946bdf5dfbb71c518703"
87
+
88
+ # If false, will attempt to open a browser window on start.
89
+ # Default: false unless (1) we are on a Linux box where DISPLAY is unset, or (2) we are running in the Streamlit Atom plugin.
90
+ # headless = false
91
+
92
+ # Automatically rerun script when the file is modified on disk.
93
+ # Default: false
94
+ # runOnSave = false
95
+
96
+ # The address where the server will listen for client and browser connections. Use this if you want to bind the server to a specific address. If set, the server will only be accessible from this address, and not from any aliases (like localhost).
97
+ # Default: (unset)
98
+ # address =
99
+
100
+ # The port where the server will listen for browser connections.
101
+ # Default: 8501
102
+ # port = 8501
103
+
104
+ # The base path for the URL where Streamlit should be served from.
105
+ # Default: ""
106
+ # baseUrlPath = ""
107
+
108
+ # Enables support for Cross-Origin Request Sharing (CORS) protection, for added security.
109
+ # Due to conflicts between CORS and XSRF, if `server.enableXsrfProtection` is on and `server.enableCORS` is off at the same time, we will prioritize `server.enableXsrfProtection`.
110
+ # Default: true
111
+ # enableCORS = true
112
+
113
+ # Enables support for Cross-Site Request Forgery (XSRF) protection, for added security.
114
+ # Due to conflicts between CORS and XSRF, if `server.enableXsrfProtection` is on and `server.enableCORS` is off at the same time, we will prioritize `server.enableXsrfProtection`.
115
+ # Default: true
116
+ # enableXsrfProtection = true
117
+
118
+ # Max size, in megabytes, for files uploaded with the file_uploader.
119
+ # Default: 200
120
+ # maxUploadSize = 200
121
+
122
+ # Max size, in megabytes, of messages that can be sent via the WebSocket connection.
123
+ # Default: 200
124
+ # maxMessageSize = 200
125
+
126
+ # Enables support for websocket compression.
127
+ # Default: false
128
+ # enableWebsocketCompression = false
129
+
130
+
131
+ [browser]
132
+
133
+ # Internet address where users should point their browsers in order to connect to the app. Can be IP address or DNS name and path.
134
+ # This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser
135
+ # Default: 'localhost'
136
+ # serverAddress = "localhost"
137
+
138
+ # Whether to send usage statistics to Streamlit.
139
+ # Default: true
140
+ # gatherUsageStats = true
141
+
142
+ # Port where users should point their browsers in order to connect to the app.
143
+ # This is used to: - Set the correct URL for CORS and XSRF protection purposes. - Show the URL on the terminal - Open the browser
144
+ # Default: whatever value is set in server.port.
145
+ # serverPort = 8501
146
+
147
+
148
+ [mapbox]
149
+
150
+ # Configure Streamlit to use a custom Mapbox token for elements like st.pydeck_chart and st.map. To get a token for yourself, create an account at https://mapbox.com. It's free (for moderate usage levels)!
151
+ # Default: ""
152
+ # token = ""
153
+
154
+
155
+ [deprecation]
156
+
157
+ # Set to false to disable the deprecation warning for the file uploader encoding.
158
+ # Default: true
159
+ # showfileUploaderEncoding = true
160
+
161
+ # Set to false to disable the deprecation warning for using the global pyplot instance.
162
+ # Default: true
163
+ # showPyplotGlobalUse = true
164
+
165
+
166
+ [theme]
167
+
168
+ # The preset Streamlit theme that your custom theme inherits from. One of "light" or "dark".
169
+ # base =
170
+
171
+ # Primary accent color for interactive elements.
172
+ # primaryColor =
173
+
174
+ # Background color for the main content area.
175
+ # backgroundColor =
176
+
177
+ # Background color used for the sidebar and most interactive widgets.
178
+ # secondaryBackgroundColor =
179
+
180
+ # Color used for almost all text.
181
+ # textColor =
182
+
183
+ # Font family for all text in the app, except code blocks. One of "sans serif", "serif", or "monospace".
184
+ # font =
185
+
186
+
.streamlit/config.toml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [theme]
2
+ font = "monospace" # "sans serif"
3
+ textColor = "#1F5BAC"
4
+ primaryColor = "#1F5BAC"
5
+ backgroundColor = "#FFFFFF"
6
+ secondaryBackgroundColor = "#F5F7FA"
7
+
8
+ [server]
9
+ #port = 8501
10
+ headless = true
11
+ address = "0.0.0.0"
12
+ #--server.enableXsrfProtection false
13
+ #--server.enableCORS false
14
+ #--server.enableWebsocketCompression=false
15
+
16
+ [browser]
17
+ gatherUsageStats = false
18
+ #--browser.serverAddress 0.0.0.0
19
+ #--browser.serverPort 8080
20
+
21
+ #[global]
22
+ #developmentMode = false
23
+
24
+ #[general] # credentials.toml
25
+ #email = "[email protected]
26
+
Dockerfile ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ # Set up a new user named "user" with user ID 1000
10
+ RUN useradd -m -u 1000 user
11
+ # Switch to the "user" user
12
+ USER user
13
+ # Set home to the user's home directory
14
+ ENV HOME=/home/user \
15
+ PATH=/home/user/.local/bin:$PATH
16
+
17
+ # Set the working directory to the user's home directory
18
+ WORKDIR $HOME/app
19
+
20
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
21
+ COPY --chown=user . $HOME/app
22
+
23
+ CMD ["sh", "run.sh"]
README.md CHANGED
@@ -1,11 +1,12 @@
1
  ---
2
  title: Nice
3
- emoji: 💩
4
  colorFrom: purple
5
  colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  license: apache-2.0
 
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Nice
3
+ emoji: 🔥
4
  colorFrom: purple
5
  colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  license: apache-2.0
9
+ app_port: 9955
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
_👋_.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(
4
+ page_title='Streamlit组件清单',
5
+ page_icon="📖",
6
+ layout="wide",
7
+ initial_sidebar_state="expanded",
8
+ )
9
+ st.text_input('业务搜索', '知识图谱')
git_init.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+
3
+ #git config --global credential.helper store
4
+
5
+ git add ./*
6
+ git commit -m "update" # git commit --amend -m '重新commit'
7
+
8
+ git pull
9
+ git push -f
packages.txt ADDED
File without changes
pages/0_留言板.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+ from appzoo.streamlit_app import Page
3
+
4
+ import streamlit as st
5
+ from streamlit.components.v1 import html, iframe
6
+
7
+
8
+ class MyPage(Page):
9
+
10
+ def main(self):
11
+ text = ""
12
+ with open("./data/x.html") as fp: # 如果遇到decode错误,就加上合适的encoding
13
+ text = fp.read()
14
+ html(text)
15
+
16
+
17
+ if __name__ == '__main__':
18
+ MyPage().main()
pages/1000_文本标识.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 8000_文本标识
5
+ # @Time : 2022/10/17 下午1:39
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import streamlit as st
13
+ from annotated_text import annotated_text, annotation
14
+
15
+ annotated_text(
16
+ "我 ",
17
+ ("热爱", "", "#8ef"),
18
+ " 我们 ",
19
+ ("非常棒", "", "#faa"),
20
+ ("而", "", "#afa"),
21
+ " 有用的 ",
22
+ ("Streamlit", "", "#fea"),
23
+ ("社区", "", "#8ef"),
24
+ ("!", "", "#afa"),
25
+ )
26
+
27
+ annotated_text(
28
+ "I ",
29
+ ("Love", "", "#8ef"),
30
+ " our ",
31
+ ("Great", "", "#faa"),
32
+ ("and", "", "#afa"),
33
+ " Useful ",
34
+ ("Streamlit", "", "#fea"),
35
+ ("Community", "", "#8ef"),
36
+ ("!", "", "#afa"),
37
+ )
38
+
pages/1001_多选组件.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 1001_多选组件
5
+ # @Time : 2022/10/17 下午1:41
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+ import streamlit as st
12
+ from streamlit_tree_select import tree_select
13
+ nodes = [
14
+ {"label": "北京", "value": "北京"},
15
+ {
16
+ "label": "上海",
17
+ "value": "上海",
18
+ "children": [
19
+ {"label": "浦东", "value": "浦东"},
20
+ {"label": "杨浦", "value": "杨浦"},
21
+ {"label": "虹口", "value": "虹口"},
22
+ {"label": "黄浦", "value": "黄浦"},
23
+ ],
24
+ },
25
+ {
26
+ "label": "广州",
27
+ "value": "广州",
28
+ "children": [
29
+ {"label": "番禺区", "value": "番禺区"},
30
+ {
31
+ "label": "白云区",
32
+ "value": "白云区",
33
+ "children": [
34
+ {"label": "三元里街", "value": "三元里街"},
35
+ {"label": "松洲街", "value": "松洲街"},
36
+ ],
37
+ },
38
+ {"label": "珠江新区", "value": "珠江新区"},
39
+ ],
40
+ },
41
+ ]
42
+
43
+ c1, c2 = st.columns(2)
44
+
45
+ with c1:
46
+
47
+ return_select = tree_select(nodes)
48
+
49
+ with c2:
50
+ st.write(return_select["checked"])
51
+
pages/1002_pandas_profiling.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 1002_profile
5
+ # @Time : 2022/10/17 下午2:34
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import pandas as pd
13
+ import pandas_profiling
14
+ import streamlit as st
15
+
16
+ from streamlit_pandas_profiling import st_profile_report
17
+
18
+ df = pd.read_csv("./data/train.csv")
19
+ pr = df.profile_report()
20
+
21
+ st_profile_report(pr)
pages/1003_streamlit_authenticator.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+
3
+ import streamlit as st
4
+ import streamlit_authenticator as stauth
5
+ from streamlit_authenticator import Authenticate
6
+
7
+ from streamlit_option_menu import option_menu
8
+
9
+ # https://github.com/mkhorasani/Streamlit-Authenticator
10
+
11
+ st.set_page_config(page_title="Platform tester", page_icon=":rainbow:", layout="centered", initial_sidebar_state="auto")
12
+ # 如下代码数据,可以来自数据库
13
+ hashed_passwords = stauth.Hasher(['123', '456']).generate()
14
+ print(hashed_passwords)
15
+
16
+ _ = f"""
17
+ credentials:
18
+ usernames:
19
+ nesc:
20
21
+ name: nesc
22
+ password: {hashed_passwords[0]} # To be replaced with hashed password
23
+
24
+ jsmith:
25
26
+ name: John Smith
27
+ password: 123 # To be replaced with hashed password
28
+
29
+ rbriggs:
30
31
+ name: Rebecca Briggs
32
+ password: 456 # To be replaced with hashed password
33
+
34
+ x:
35
36
+ name: x
37
+ password: xxx # To be replaced with hashed password
38
+ cookie:
39
+ expiry_days: 30
40
+ key: some_signature_key
41
+ name: some_cookie_name
42
+ preauthorized:
43
+ emails:
44
45
+ """
46
+
47
+ config = yaml.load(_)
48
+
49
+ authenticator = Authenticate(
50
+ config['credentials'],
51
+ config['cookie']['name'],
52
+ config['cookie']['key'],
53
+ config['cookie']['expiry_days'],
54
+ config['preauthorized']
55
+ )
56
+
57
+ name, authentication_status, username = authenticator.login('Login', 'main')
58
+
59
+ if authentication_status:
60
+ authenticator.logout('Logout', 'main')
61
+ st.write(f'Welcome *{name}*')
62
+ st.title('Some content')
63
+ elif authentication_status == False:
64
+ st.error('Username/password is incorrect')
65
+ elif authentication_status == None:
66
+ st.warning('Please enter your username and password')
67
+
68
+
69
+ if authentication_status:
70
+ try:
71
+ if authenticator.reset_password(username, 'Reset password'):
72
+ st.success('Password modified successfully')
73
+ except Exception as e:
74
+ st.error(e)
75
+
76
+
77
+ try:
78
+ if authenticator.register_user('Register user', preauthorization=False):
79
+ st.success('User registered successfully')
80
+ except Exception as e:
81
+ st.error(e)
82
+
83
+
84
+ try:
85
+ username_forgot_pw, email_forgot_password, random_password = authenticator.forgot_password('Forgot password')
86
+ if username_forgot_pw:
87
+ st.success('New password sent securely')
88
+ # Random password to be transferred to user securely
89
+ elif username_forgot_pw == False:
90
+ st.error('Username not found')
91
+ except Exception as e:
92
+ st.error(e)
pages/1004_streamlit_option_menu.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+
3
+ import streamlit as st
4
+ from streamlit_option_menu import option_menu
5
+
6
+ st.set_page_config(page_title="Option Menu", layout="wide")
7
+ with st.sidebar:
8
+ selected = option_menu("Main Menu", ["Home", "Upload", "---", "Tasks", 'Settings'],
9
+ icons=['house', 'cloud-upload', None, "list-task", 'gear'], menu_icon="cast",
10
+ default_index=1)
11
+
12
+ selected2 = option_menu(None, ["Home", "Upload", "---", "Tasks", 'Settings'],
13
+ icons=['house', 'cloud-upload', None, "list-task", 'gear'],
14
+ menu_icon="cast", default_index=0, orientation="horizontal")
15
+
16
+ selected3 = option_menu(None, ["Home", "Upload", "Tasks", 'Settings'],
17
+ icons=['house', 'cloud-upload', "list-task", 'gear'],
18
+ menu_icon="cast", default_index=0, orientation="horizontal",
19
+ styles={
20
+ "container": {"padding": "0!important", "background-color": "#fafafa"},
21
+ "icon": {"color": "orange", "font-size": "25px"},
22
+ "nav-link": {"font-size": "25px", "text-align": "left", "margin": "0px",
23
+ "--hover-color": "#eee"},
24
+ "nav-link-selected": {"background-color": "green"},
25
+ }
26
+ )
27
+
28
+ # choice = option_menu(
29
+ # "Menu", ["首页", "HIVE", "KUDU", "MYSQL"],
30
+ # icons=['house', 'chat-square', 'chat-square-dots', 'chat-square-text'], menu_icon="hammer",
31
+ # default_index=0)
32
+
33
+ # df.style.set_precision
pages/111_📚_PDF简单表格提取.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 111_📚_PDF简单表格提取
5
+ # @Time : 2022/11/3 下午6:09
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ from appzoo.streamlit_app import Page
13
+ import streamlit as st
14
+ from st_aggrid import AgGrid
15
+
16
+ import camelot
17
+
18
+
19
+ class MyPage(Page):
20
+
21
+ def main(self):
22
+ with st.form("Coding"):
23
+ file = st.file_uploader("选择待上传的PDF文件", type=['pdf', 'docx', 'xlsx'])
24
+ if file:
25
+ open(file.name, 'wb').write(file.read())
26
+
27
+ if st.form_submit_button('开始转换'):
28
+ tables = camelot.read_pdf(file.name)
29
+ df = tables[0].df
30
+ print(df)
31
+
32
+ st.dataframe(df)
33
+
34
+
35
+ if __name__ == '__main__':
36
+ app_title = "# 切词"
37
+ app_info = ""
38
+ MyPage(app_title=app_title, app_info=app_info, layout='wide').main()
pages/112_📚_简单的配置界面.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 111_📚_PDF简单表格提取
5
+ # @Time : 2022/11/3 下午6:09
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ from appzoo.streamlit_app import Page
13
+ import streamlit as st
14
+ from meutils.pipe import *
15
+ from meutils.path_utils import file2json
16
+
17
+
18
+ class MyPage(Page):
19
+
20
+ def main(self):
21
+ cfg = file2json(get_resolve_path('../data/config.yml', __file__) )
22
+ st.json(cfg)
23
+
24
+
25
+ if __name__ == '__main__':
26
+ app_title = "# 配置"
27
+ MyPage(app_title=app_title, layout='wide').main()
pages/113_💰_穿透.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 111_📚_PDF简单表格提取
5
+ # @Time : 2022/11/3 下午6:09
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ from appzoo.streamlit_app import Page
13
+ import streamlit as st
14
+ from meutils.pipe import *
15
+ from meutils.path_utils import file2json
16
+
17
+
18
+ class MyPage(Page):
19
+
20
+ def main(self):
21
+ cfg = file2json(get_resolve_path('../data/config.yml', __file__) )
22
+ st.json(cfg)
23
+
24
+
25
+ if __name__ == '__main__':
26
+ app_title = "# 配置"
27
+ MyPage(app_title=app_title, layout='wide').main()
pages/1_🔥_模型生成代码.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+ from appzoo.streamlit_app import Page
3
+
4
+ import streamlit as st
5
+
6
+ import m2cgen as m2c
7
+
8
+
9
+ class MyPage(Page):
10
+
11
+ def main(self):
12
+ with st.form("Coding"):
13
+ file = st.file_uploader('上传默模型文件')
14
+ if file:
15
+ estimator = joblib.load(file)
16
+ else:
17
+ estimator = joblib.load(get_resolve_path('../data/lr.pkl', __file__))
18
+
19
+ languages = [
20
+ 'python',
21
+ 'java',
22
+ 'go',
23
+ 'c',
24
+ 'c_sharp',
25
+ 'r',
26
+ 'dart',
27
+ 'elixir',
28
+ 'f_sharp',
29
+ 'haskell',
30
+ 'javascript',
31
+ 'php',
32
+ 'powershell',
33
+ 'ruby',
34
+ 'rust',
35
+ 'visual_basic'
36
+ ]
37
+
38
+ _ = st.selectbox('选择输出语言', languages)
39
+
40
+ if st.form_submit_button('开始转换'):
41
+ code = m2c.__getattribute__(f'export_to_{_}')(estimator)
42
+
43
+ st.markdown("##### code:")
44
+ st.code(code)
45
+
46
+
47
+
48
+ if __name__ == '__main__':
49
+ app_title = "ModelToCode"
50
+ app_info = """
51
+ 将训练过的统计模型转化为本地代码(`Python, C, Java, Go, JavaScript, Visual Basic, c#, PowerShell, R, PHP, Dart, Haskell, Ruby, f#, Rust, Elixir`)。
52
+ """
53
+ MyPage(
54
+ app_title=f"# {app_title}",
55
+ app_info=f"> {app_info}",
56
+ ).main()
pages/2_📚_PDF预览.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+ from appzoo.streamlit_app import Page
3
+
4
+ import streamlit as st
5
+ import streamlit.components.v1 as components
6
+
7
+ class MyPage(Page):
8
+ """
9
+ https://zhuanlan.zhihu.com/p/518115802?utm_medium=social&utm_oi=1290068536690085888
10
+ """
11
+
12
+ def main(self):
13
+
14
+
15
+ with st.form("PDF"):
16
+ file = st.file_uploader("选择待上传的PDF文件", type=['pdf', 'docx', 'xlsx'])
17
+
18
+ if st.form_submit_button('开始预览', help='先上传文件!!!'):
19
+ if file is not None:
20
+ base64_pdf = base64.b64encode(file.read()).decode('utf-8')
21
+
22
+ self.display_pdf(base64_pdf, width='100%', height=1000)
23
+ self.display_html()
24
+
25
+ def display_pdf(self, base64_pdf, width='100%', height=1000):
26
+ # https://blog.51cto.com/laok8/2395498
27
+ pdf_display = f"""<embed src="data:application/pdf;base64,{base64_pdf}" width="{width}" height="{height}" type="application/pdf">"""
28
+ # data_type = 'vnd.openxmlformats-officedocument.wordprocessingml.document'
29
+ # pdf_display = f"""<embed src="data:application/{data_type};base64,{base64_pdf}" width="{width}" height="{height}" type="application/{data_type}">"""
30
+
31
+ st.markdown(pdf_display, unsafe_allow_html=True)
32
+
33
+ def display_html(self, text='会飞的文字'):
34
+ _ = f"""
35
+ <marquee direction="down" width="100%" height="100%" behavior="alternate" style="border:solid" bgcolor="#00FF00">
36
+
37
+ <marquee behavior="alternate">
38
+
39
+ {text}
40
+
41
+ </marquee>
42
+
43
+ </marquee>
44
+ """
45
+ st.markdown(_, unsafe_allow_html=True)
46
+
47
+ if __name__ == '__main__':
48
+ app_title = "# PDF应用"
49
+ app_info = "PDF预览"
50
+ MyPage(
51
+ app_title=app_title,
52
+ app_info=app_info,
53
+ ).main()
pages/3_🐧_分词.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+
3
+ from appzoo.streamlit_app import Page
4
+
5
+ import streamlit as st
6
+
7
+ from LAC import LAC as _LAC
8
+
9
+ LAC = st.experimental_singleton(_LAC)
10
+
11
+
12
+ # @st.cache(func=None, persist=False, hash_funcs={'LAC.lac.LAC': str})
13
+ # def tokenizer():
14
+ # print('Loading tokenizer1...')
15
+ # return LAC()
16
+
17
+ @ttl_cache(key=str)
18
+ @disk_cache()
19
+ def tokenizer(texts):
20
+ return LAC().run(texts) | xmap_(lambda r: list(zip(*r)))
21
+
22
+
23
+ class MyPage(Page):
24
+
25
+ def main(self):
26
+ with st.form("Coding"):
27
+
28
+ texts = st.text_area("输入文本", ["为什么东北证券那么牛?"]*3 | xjoin('\n')).split("\n")
29
+
30
+ if st.form_submit_button('开始转换'):
31
+ _ = tokenizer(texts)
32
+
33
+ # st.json(_)
34
+ # st.text(_)
35
+ # st.dataframe(pd.DataFrame(_))
36
+
37
+
38
+ from annotated_text import annotated_text
39
+
40
+ for text in _:
41
+ annotated_text(*text)
42
+
43
+
44
+ if __name__ == '__main__':
45
+ app_title = "# 切词"
46
+ app_info = ""
47
+ MyPage(app_title=app_title, app_info=app_info).main()
pages/4_🤩_Apps.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from urllib.parse import urlencode, parse_qs, parse_qsl, quote_plus, unquote_plus
3
+
4
+ # query_params = st.session_state.get("initial_query_params", {})
5
+ query_params = st.experimental_get_query_params()
6
+ query_params = {k: v[0] for k, v in query_params.items()}
7
+
8
+
9
+ # st.experimental_set_query_params(parse_qs('a=b&c=d')) # parse_qs
10
+ st.write("Initial query params of the session:", query_params)
11
+
12
+ if query_params.get('appid') == '1':
13
+ st.markdown("# App1")
14
+
15
+ elif query_params.get('appid') == '2':
16
+ st.markdown("# App2")
17
+
18
+
19
+ import time
20
+
21
+ st.session_state.file = time.time()
22
+
23
+ st.write(st.session_state.file)
pages/5_👍_Postman.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+ from meutils.request_utils import request4retry
3
+
4
+ from appzoo.streamlit_app import Page
5
+
6
+ import streamlit as st
7
+ from streamlit.components.v1 import html, iframe
8
+
9
+
10
+ class MyPage(Page):
11
+
12
+ def main(self):
13
+ with st.form("Coding"):
14
+ col, *_ = st.columns(4)
15
+ method = col.selectbox('method', ['GET', 'POST'])
16
+
17
+ url = st.text_input('url')
18
+ data = st.text_area('data', {})
19
+ data = json.loads(data)
20
+ kwargs = {}
21
+
22
+ if st.form_submit_button("开始请求"):
23
+ _ = requests.request(method, url, json=data, **kwargs)
24
+ return st.json(_)
25
+
26
+
27
+ if __name__ == '__main__':
28
+ MyPage(layout='wide').main()
pages/6666_🐧_hr.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from meutils.pipe import *
2
+
3
+ from appzoo.streamlit_app import Page
4
+
5
+ import streamlit as st
6
+
7
+ from aip import AipOcr
8
+
9
+ APP_ID, API_KEY, SECRET_KEY = "25308860,GmAPqlyBDNLaoAqO2mrFhjS2,vXIoxFUdx2jiuRnGLvZSDMEczEaZsc1K".split(',')
10
+
11
+ client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
12
+
13
+ """ 读取图片 """
14
+
15
+
16
+ def get_file_content(filePath):
17
+ with open(filePath, 'rb') as fp:
18
+ return fp.read()
19
+
20
+
21
+ """ 如果有可选参数 """
22
+ options = {}
23
+ options["language_type"] = "CHN_ENG"
24
+ options["detect_direction"] = "true"
25
+ options["detect_language"] = "true"
26
+ options["probability"] = "true"
27
+
28
+
29
+ class MyPage(Page):
30
+
31
+ def main(self):
32
+ with st.form("Coding"):
33
+ file = st.file_uploader("请上传不动产证明😄", "")
34
+
35
+ if st.form_submit_button('开始认证'):
36
+ if file:
37
+ r = client.basicGeneral(file.read())
38
+ r = '\n'.join(list(map(lambda d: d.get('words'), r['words_result'][4:11])))
39
+ st.text(r)
40
+
41
+ else:
42
+ st.markdown("# 请上传不动产证明😄再点认证👆🏻")
43
+ _ = '2022年11月16日,根据查询人\n张三李四\n申请,经查询,结果如下:\n编号:\n202211160344242218\n坐落\n雨花台区西善桥街道云上润府观庭 - 6幢6单元2206室'
44
+ st.text(_)
45
+
46
+
47
+ if __name__ == '__main__':
48
+ app_title = "# 认证"
49
+ app_info = ""
50
+ MyPage(app_title=app_title, app_info=app_info).main()
pages/666_😝_TEST.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 666_😝_TEST
5
+ # @Time : 2023/3/9 上午10:28
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description : https://github.com/streamlit/example-app-commenting/blob/main/streamlit_app.py
10
+
11
+
12
+ """
13
+ 不断刷新数据图表
14
+ https://blog.csdn.net/qq_42761569/article/details/123418493
15
+ http://cw.hubwiz.com/card/c/streamlit-manual/1/6/13/
16
+ """
17
+ import altair as alt
18
+
19
+
20
+ def get_chart(data):
21
+ # 鼠标悬停
22
+ hover = alt.selection_single(
23
+ fields=["date"],
24
+ nearest=True,
25
+ on="mouseover",
26
+ empty="none",
27
+ )
28
+
29
+ lines = (
30
+ alt.Chart(data, title="Evolution of stock prices")
31
+ .mark_line()
32
+ .encode(
33
+ x="date",
34
+ y="price",
35
+ color="symbol",
36
+ strokeDash="symbol",
37
+ )
38
+ )
39
+
40
+ # Draw points on the line, and highlight based on selection
41
+ points = lines.transform_filter(hover).mark_circle(size=65)
42
+
43
+ # Draw a rule at the location of the selection
44
+ tooltips = (
45
+ alt.Chart(data)
46
+ .mark_rule()
47
+ .encode(
48
+ x="date",
49
+ y="price",
50
+ opacity=alt.condition(hover, alt.value(0.3), alt.value(0)),
51
+ tooltip=[
52
+ alt.Tooltip("date", title="Date"),
53
+ alt.Tooltip("price", title="Price (USD)"),
54
+ ],
55
+ )
56
+ .add_selection(hover)
57
+ )
58
+
59
+ return (lines + points + tooltips).interactive()
60
+
61
+
62
+ # source = data.stocks()
63
+ # all_symbols = source.symbol.unique()
64
+ # symbols = st.multiselect("Choose stocks to visualize", all_symbols, all_symbols[:3])
65
+ #
66
+ #
67
+ # source = source[source.symbol.isin(symbols)]
68
+ # chart = get_chart(source)
69
+ # st.altair_chart(chart, use_container_width=True)
pages/66_🔥_ASCII字符画.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from numpy import load
3
+ from numpy import expand_dims
4
+ from matplotlib import pyplot
5
+ from PIL import Image, ImageDraw, ImageFont, ImageFile
6
+ import numpy as np
7
+ import os
8
+
9
+ st.set_page_config(page_title='ASCII字符画生成器', page_icon="🅰", layout="wide")
10
+
11
+ st.header("上传一张图片生成ASCII字符画")
12
+
13
+ ImageFile.LOAD_TRUNCATED_IMAGES = True
14
+ Image.MAX_IMAGE_PIXELS = None
15
+
16
+ color_fornt = st.sidebar.color_picker('选择前景色', '#00b8e6')
17
+ color_background = st.sidebar.color_picker('选择背景色', '#ffffff')
18
+
19
+ sc_control = st.sidebar.slider('选择密度参数1', 0.1, 0.9, 0.5, 0.1)
20
+ gcf_control = st.sidebar.slider('选择密度参数2', 0.5, 4.5, 2.1, 0.1)
21
+
22
+ uploaded_file = st.file_uploader("选择一张图片", type=["png", "jpg", "bmp", "jpeg"])
23
+
24
+
25
+ @st.cache()
26
+ def asciiart(in_f, SC, GCF, out_f, bgcolor=color_background):
27
+ chars = np.asarray(list(' .,:irs?@9B&#*$%!~'))
28
+
29
+ font = ImageFont.load_default()
30
+ letter_width = font.getsize("x")[0]
31
+ letter_height = font.getsize("x")[1]
32
+ WCF = letter_height / letter_width
33
+ img = Image.open(in_f)
34
+ widthByLetter = round(img.size[0] * SC * WCF)
35
+ heightByLetter = round(img.size[1] * SC)
36
+ S = (widthByLetter, heightByLetter)
37
+ img = img.resize(S)
38
+ img = np.sum(np.asarray(img), axis=2)
39
+ img -= img.min()
40
+ img = (1.0 - img / img.max()) ** GCF * (chars.size - 1)
41
+ lines = ("\n".join(("".join(r) for r in chars[img.astype(int)]))).split("\n")
42
+ nbins = len(lines)
43
+ newImg_width = letter_width * widthByLetter
44
+ newImg_height = letter_height * heightByLetter
45
+ newImg = Image.new("RGBA", (newImg_width, newImg_height), bgcolor)
46
+ draw = ImageDraw.Draw(newImg)
47
+ leftpadding = 0
48
+ y = 0
49
+ lineIdx = 0
50
+
51
+ for line in lines:
52
+ color = color_fornt
53
+ lineIdx += 1
54
+ draw.text((leftpadding, y), line, color, font=font)
55
+ y += letter_height
56
+
57
+ newImg.save(out_f)
58
+
59
+
60
+ @st.cache()
61
+ def load_image(filename, size=(512, 512)):
62
+ pixels = load_img(filename, target_size=size)
63
+ pixels = img_to_array(pixels)
64
+ pixels = (pixels - 127.5) / 127.5
65
+ pixels = expand_dims(pixels, 0)
66
+ return pixels
67
+
68
+
69
+ @st.cache()
70
+ def imgGen2(img1):
71
+ inputf = img1
72
+ SC = sc_control
73
+ GCF = gcf_control
74
+ asciiart(inputf, SC, GCF, "results.png", color_background)
75
+ img = Image.open(img1)
76
+ img2 = Image.open('results.png').resize(img.size)
77
+
78
+ return img2
79
+
80
+
81
+ # 下载按钮效果设置
82
+ css = """<style>
83
+ .stDownloadButton>button {
84
+ background-color: #0099ff;
85
+ color:#ffffff;
86
+ }
87
+
88
+ .stDownloadButton>button:hover {
89
+ background-color: green;
90
+ color:white;
91
+ }
92
+ </style>
93
+ """
94
+ st.markdown(css, unsafe_allow_html=True)
95
+
96
+ if uploaded_file is not None:
97
+ st.sidebar.image(uploaded_file, caption='原始图片', use_column_width=True)
98
+ im = imgGen2(uploaded_file)
99
+ st.image(im, width=700)
100
+ with open("results.png", "rb") as file:
101
+ # st.image("图片.jpg")
102
+ btn = st.download_button(
103
+ label="点我下载生成的ASCII字符画",
104
+ data=file,
105
+ file_name="ASCII字符画.png",
106
+ mime="image/png"
107
+ )
pages/6_🕷_coding.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 6_🕷_coding
5
+ # @Time : 2022/10/27 下午4:54
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import streamlit as st
13
+
14
+ from streamlit_ace import st_ace
15
+
16
+ # Spawn a new Ace editor
17
+ content = st_ace()
18
+
19
+ # Display editor's content as you type
20
+ content
pages/7_登录.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 7_登录
5
+ # @Time : 2023/3/14 下午4:02
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+ import wenxin_api
12
+ from wenxin_api.tasks.text_to_image import TextToImage
13
+
14
+ import streamlit as st
15
+ import streamlit_authenticator as stauth
16
+ from streamlit_authenticator import Authenticate
17
+
18
+ # ME
19
+ from meutils.pipe import *
20
+
21
+ st.set_page_config(page_title="文本标注平台", page_icon=":rainbow:", layout="centered", initial_sidebar_state="auto")
22
+
23
+ # 如下代码数据,可以来自数据库
24
+ admin_password = '123456'
25
+
26
+ _ = f"""
27
+ credentials:
28
+ usernames:
29
+ admin:
30
31
+ name: admin
32
+ password: {stauth.Hasher([admin_password]).generate()[0]} # To be replaced with hashed password
33
+
34
+ cookie:
35
+ expiry_days: 30
36
+ key: some_signature_key
37
+ name: some_cookie_name
38
+ preauthorized:
39
+
40
+ emails:
41
42
+ """
43
+
44
+ config = yaml.safe_load(_)
45
+
46
+ authenticator = Authenticate(
47
+ config['credentials'],
48
+ config['cookie']['name'],
49
+ config['cookie']['key'],
50
+ config['cookie']['expiry_days'],
51
+ config['preauthorized']
52
+ )
53
+
54
+ name, authentication_status, username = authenticator.login('图像生成系统', 'main')
55
+
56
+ if authentication_status:
57
+ authenticator.logout('退出', 'sidebar')
58
+ st.write('# 图像生成系统')
59
+
60
+ elif authentication_status == False:
61
+ st.error('Username/password is incorrect')
62
+
63
+ # elif authentication_status == None:
64
+ # st.warning('Please enter your username and password')
pages/888_🌰_demo.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from urllib.parse import urlencode, parse_qs
2
+ import streamlit as st
3
+
4
+
5
+ st.json(st.session_state)
6
+ initial_query_params = st.session_state.get("initial_query_params")
7
+ query_params = {k: v[0] for k, v in st.experimental_get_query_params().items()}
8
+ if not initial_query_params:
9
+ initial_query_params = query_params.copy()
10
+ st.session_state["initial_query_params"] = initial_query_params.copy()
11
+
12
+ st.write("Initial query params of the session:", initial_query_params)
13
+ st.write("Query params before setting new ones:", query_params)
14
+
15
+ new_query_string = st.text_area("New query params string (like 'a=b&c=d')", value=urlencode(initial_query_params))
16
+ if st.button("Set new query params without starting new session"):
17
+ st.experimental_set_query_params(**parse_qs(new_query_string))
18
+
19
+ with st.sidebar:
20
+ st.markdown("---")
21
+ st.markdown(
22
+ '<h6>Made in &nbsp<img src="https://streamlit.io/images/brand/streamlit-mark-color.png" alt="Streamlit logo" height="16">&nbsp by <a href="https://twitter.com/andfanilo">@andfanilo</a></h6>',
23
+ unsafe_allow_html=True,
24
+ )
25
+ st.markdown(
26
+ '<div style="margin-top: 0.75em;"><a href="https://www.buymeacoffee.com/andfanilo" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174"></a></div>',
27
+ unsafe_allow_html=True,
28
+ )
29
+ st.json(st.session_state)
pages/889_机器监控.py ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 991_streamlit_apex_charts
5
+ # @Time : 2022/10/17 上午10:48
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import psutil
13
+ import streamlit as st
14
+ import time
15
+ import datetime
16
+ from streamlit_autorefresh import st_autorefresh
17
+ from streamlit_apex_charts import bar_chart, pie_chart
18
+ import pandas as pd
19
+ import platform
20
+ import os
21
+
22
+
23
+ st.set_page_config(page_title="系统信息查看器", page_icon="💻", layout="wide")
24
+
25
+ #st_autorefresh(interval=5000, limit=100000, key="Mr.R")
26
+
27
+ st.header("系统信息查看器")
28
+ base_infor = [[datetime.datetime.now().strftime("%Y-%m-%d %H: %M: %S"),str(psutil.users()[0][0]),platform.platform()]]
29
+ df_base_infor = pd.DataFrame(base_infor, columns=["当前时间","登陆者","操作系统"])
30
+ st.table(df_base_infor)
31
+
32
+ #获取网卡名称
33
+ def get_key():
34
+ key_info = psutil.net_io_counters(pernic=True).keys() # 获取网卡名称
35
+ recv = {}
36
+ sent = {}
37
+ for key in key_info:
38
+ recv.setdefault(key, psutil.net_io_counters(pernic=True).get(key).bytes_recv) # 各网卡接收的字节数
39
+ sent.setdefault(key, psutil.net_io_counters(pernic=True).get(key).bytes_sent) # 各网卡发送的字节数
40
+ return key_info, recv, sent
41
+
42
+ #获取网卡速率
43
+ def get_rate(func):
44
+ key_info, old_recv, old_sent = func() # 上一秒收集的数据
45
+ time.sleep(1)
46
+ key_info, now_recv, now_sent = func() # 当前所收集的数据
47
+ net_in = {}
48
+ net_out = {}
49
+ for key in key_info:
50
+ net_in.setdefault(key, (now_recv.get(key) - old_recv.get(key)) / 1024) # 每秒接收速率
51
+ net_out.setdefault(key, (now_sent.get(key) - old_sent.get(key)) / 1024) # 每秒发送速率
52
+ return key_info, net_in, net_out
53
+
54
+
55
+ c1, c2, c3 = st.columns(3)
56
+
57
+ with c1:
58
+ #内存
59
+ mem = psutil.virtual_memory()
60
+ zj = float(mem.total) / 1024 / 1024 / 1024
61
+ ysy = float(mem.used) / 1024 / 1024 / 1024
62
+ kx = float(mem.free) / 1024 / 1024 / 1024
63
+
64
+ data_neicun = [[round(ysy,2),round(kx, 2)]]
65
+ df_neicun = pd.DataFrame(data_neicun, columns=["已用内存","空闲内存"])
66
+ pie_chart("内存使用情况(GB)", df_neicun)
67
+
68
+
69
+ #CPU
70
+ cpu_liyonglv = (str(psutil.cpu_percent(1))) + '%'
71
+ cpu_data = [[cpu_liyonglv]]
72
+ df_cpu = pd.DataFrame(cpu_data, columns=["CPU利用率"])
73
+ bar_chart("CPU利用率(%)", df_cpu)
74
+
75
+ with c2:
76
+ #磁盘
77
+ dk = psutil.disk_usage('/')
78
+ total = dk.total / 1024 / 1024 / 1024
79
+ used = dk.used / 1024 / 1024 / 1024
80
+ free = dk.free / 1024 / 1024 / 1024
81
+
82
+ cipan_shiyong = [[used, free]]
83
+ df_cipan = pd.DataFrame(cipan_shiyong, columns=["已使用磁盘大小","空闲磁盘大小"])
84
+ pie_chart("磁盘使用率(%)", df_cipan)
85
+
86
+ #网络速率
87
+ key_info, net_in, net_out = get_rate(get_key)
88
+ wangka_liuliang = []
89
+ for key in key_info:
90
+ wangka_liuliang.append([net_in.get(key),net_out.get(key)])
91
+ speed_internet = wangka_liuliang
92
+ df_speed = pd.DataFrame(speed_internet, columns=["下行速率","上行速率"])
93
+ bar_chart("网络速率(kb/s)", df_speed)
94
+
95
+
96
+
97
+ with c3:
98
+ #进程信息
99
+ pids = psutil.pids()
100
+ process = []
101
+ for pid in pids:
102
+ p = psutil.Process(pid)
103
+ process_name = p.name()
104
+ process.append([pid, process_name, p.is_running()])
105
+
106
+ df_process = pd.DataFrame(process, columns=["PID","进程名","是否还在运行"])
107
+ st.dataframe(df_process)
108
+
109
+ # #已安装软件
110
+ # import wmi
111
+ # c = wmi.WMI()
112
+ # software_list = []
113
+ # for s in c.Win32_Product():
114
+ # software_list.append([s.Caption, s.Vendor, s.Version])
115
+ # if len(software_list)>1:
116
+ # st.dataframe(pd.DataFrame(software_list, columns=["名称","发布人","版本"]))
117
+ # else:
118
+ # st.info("正在导出已安装的软件程序列表")
pages/8_内容审核.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 8_内容审核
5
+ # @Time : 2023/3/15 上午10:40
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description : pip install baidu-aip
10
+
11
+
12
+
13
+
14
+ from functools import lru_cache
15
+ from aip import AipImageCensor, AipOcr
16
+
17
+ _ = """
18
+ 31294942
19
+ d8pnIpxUaZ7ce65StreDuOY0
20
+ lldWlW574LV8n3mIG2xQvcL6Wa7MXi5q
21
+ """.strip().split()
22
+ ai = AipImageCensor(*_)
23
+
24
+ @lru_cache()
25
+ def text_censor(text='一群垃圾去找小姐'):
26
+ data = ai.textCensorUserDefined(text).get('data', [])
27
+ rst = []
28
+ for _ in data:
29
+ d = {}
30
+ d['msg'] = _['msg']
31
+ hits = _['hits']
32
+ d['words'] = sum([hit['words'] for hit in hits], [])
33
+ rst.append(d)
34
+ return rst if rst else ['合规']
35
+
36
+ @lru_cache()
37
+ def image_censor(img): # open('hao123 logo.png', 'rb').read()
38
+ data = ai.imageCensorUserDefined(img).get('data', [])
39
+ rst = []
40
+ for _ in data:
41
+ d = {}
42
+ d['msg'] = _['msg']
43
+ # hits = _['hits']
44
+ # d['words'] = sum([hit['words'] for hit in hits], [])
45
+ rst.append(d)
46
+ return rst if rst else ['合规']
47
+
48
+ import streamlit as st
49
+
50
+ tab1, tab2, tab3 = st.tabs(["文本审核", "图片审核", "视频审核"])
51
+
52
+ with tab1:
53
+ st.header("文本审核")
54
+ text= st.text_input('请输入文本', value='一群垃圾去找小姐')
55
+ button = st.button('开始审核文本')
56
+ if button:
57
+ st.json(text_censor(text))
58
+
59
+ with tab2:
60
+ st.header("图像审核")
61
+ file = st.file_uploader('请上传图片')
62
+ button = st.button('开始审核图片')
63
+
64
+ if file and button:
65
+ col1, col2 = st.columns(2)
66
+ with col1:
67
+ st.image(file)
68
+ with col2:
69
+ st.json(image_censor(file.read()))
70
+
71
+
72
+
73
+ with tab3:
74
+ st.header("视频审核")
pages/990_streamlit_autorefresh.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_autorefresh import st_autorefresh
3
+
4
+ # Run the autorefresh about every 2000 milliseconds (2 seconds) and stop
5
+ # after it's been refreshed 100 times.
6
+ count = st_autorefresh(interval=2000, limit=100, key="fizzbuzzcounter")
7
+
8
+ # The function returns a counter for number of refreshes. This allows the
9
+ # ability to make special requests at different intervals based on the count
10
+ if count == 0:
11
+ st.write("Count is zero")
12
+ elif count % 3 == 0 and count % 5 == 0:
13
+ st.write("FizzBuzz")
14
+ elif count % 3 == 0:
15
+ st.write("Fizz")
16
+ elif count % 5 == 0:
17
+ st.write("Buzz")
18
+ else:
19
+ st.write(f"Count: {count}")
pages/991_streamlit_apex_charts.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import pandas as pd
3
+ import streamlit as st
4
+ from streamlit_apex_charts import line_chart, bar_chart, pie_chart, area_chart, radar_chart
5
+
6
+ st.set_page_config(layout="wide")
7
+
8
+ df = pd.DataFrame(np.random.randint(1, 10, size=(10, 3)), columns=['Apple', 'Microsoft', 'Google'])
9
+
10
+ line_chart('Line chart', df)
11
+ c1, c2 = st.columns(2)
12
+ with c1:
13
+ bar_chart('Bar chart', df)
14
+ pie_chart('Pie chart', df)
15
+ with c2:
16
+ area_chart('Area chart', df)
17
+ radar_chart('Radar chart', df)
18
+
19
+ # https://discuss.streamlit.io/t/new-component-streamlit-apex-charts/18769/3
pages/992_streamlit_chat.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 991_streamlit_apex_charts
5
+ # @Time : 2022/10/17 上午10:48
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+ import streamlit as st
11
+ from streamlit_chat import message
12
+
13
+ message_history = ["你好!我是你的电影小助手,很高兴为您服务。"]
14
+
15
+ for message_ in message_history:
16
+ message(message_, avatar_style='adventurer') # display all the previous message
17
+
18
+ placeholder = st.empty() # placeholder for latest message
19
+ input_ = st.text_input("请向我提问:")
20
+ message_history.append(input_)
21
+
22
+ with placeholder.container():
23
+ # message(message_history[-1], avatar_style='adventurer') # display the latest message
24
+ message(message_history[-1], is_user=True) # align's the message to the right
25
+
pages/993_streamlit_text_rating.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from streamlit_text_rating.st_text_rater import st_text_rater
2
+
3
+
4
+ import streamlit as st
5
+
6
+
7
+ st.title("Awesome App")
8
+ for text in ["Is this text helpful?", "Do you like this text?"]:
9
+ response = st_text_rater(text=text)
10
+ st.write(f"response --> {response}")
11
+
pages/994_自定义style.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 994_自定义style
5
+ # @Time : 2022/10/17 上午11:45
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import streamlit as st
13
+ from streamlit.components.v1 import html
14
+
15
+ st.button('button背景色?换一个吧')
16
+ st.text_area('del', placeholder='Label多余?删了就好')
17
+ st.radio('想放大label字号, 修改字体吗?', ['想', '很想'])
18
+
19
+ st.markdown('''<style>
20
+ /* radio label字号、字体 */
21
+ #root > div:nth-child(1) > div > div > div > div > section > div > div:nth-child(1) > div > div:nth-child(3) > div > label {
22
+ font-size: 50px;
23
+ font-family: "Times New Roman", serif;
24
+ }
25
+ /* button背景色 */
26
+ #root > div:nth-child(1) > div > div > div > div > section > div > div:nth-child(1) > div > div:nth-child(1) > div > button {
27
+ background-color: black;
28
+ color: white;
29
+ }
30
+ /* radio选中项颜色 */
31
+ #root > div:nth-child(1) > div > div > div > div > section > div > div:nth-child(1) > div > div:nth-child(3) > div > div > label:nth-child(1) > div.st-co.st-cs.st-ct.st-cu.st-cv.st-cw.st-az.st-b4.st-cx.st-cy.st-cz.st-d0.st-d1.st-d2.st-c4.st-d3.st-d4.st-d5.st-b2.st-bl {
32
+ background-color: black;
33
+ }
34
+ </style>''', unsafe_allow_html=True)
35
+
36
+ js_delete = '''window.parent.document.querySelector("#root > div:nth-child(1) > div > div > div > div > section > div > div:nth-child(1) > div > div:nth-child(2) > div > label").remove()'''
37
+ html(f'''<script>{js_delete}</script>''',
38
+ width=0,
39
+ height=0)
pages/995_streamlit_echarts.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 995_streamlit_echarts
5
+ # @Time : 2022/10/17 下午12:11
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ from streamlit_echarts import st_echarts
13
+
14
+ options = {
15
+ "xAxis": {
16
+ "type": "category",
17
+ "data": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
18
+ },
19
+ "yAxis": {"type": "value"},
20
+ "series": [
21
+ {"data": [820, 932, 901, 934, 1290, 1330, 1320], "type": "line"}
22
+ ],
23
+ }
24
+ st_echarts(options=options)
25
+
pages/996_streamlit_pyecharts.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 995_streamlit_echarts
5
+ # @Time : 2022/10/17 下午12:11
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+ from pyecharts import options as opts
12
+ from pyecharts.charts import Bar, WordCloud
13
+ from streamlit_echarts import st_pyecharts
14
+ import streamlit as st
15
+
16
+
17
+ # st.markdown(open('xx.html').read(), unsafe_allow_html=True)
18
+
19
+ tab1, tab2, tab3 = st.tabs(["Bar", "WordCloud", "Owl"])
20
+
21
+ with tab1:
22
+ b = (
23
+ Bar()
24
+ .add_xaxis(["Microsoft", "Amazon", "IBM", "Oracle", "Google", "Alibaba"])
25
+ .add_yaxis(
26
+ "2017-2018 Revenue in (billion $)", [21.2, 20.4, 10.3, 6.08, 4, 2.2]
27
+ )
28
+ .set_global_opts(
29
+ title_opts=opts.TitleOpts(
30
+ title="Top cloud providers 2018", subtitle="2017-2018 Revenue"
31
+ ),
32
+ toolbox_opts=opts.ToolboxOpts(),
33
+ )
34
+ )
35
+ st_pyecharts(b)
36
+
37
+ with tab2:
38
+ pairs = [('中国', 33),
39
+ ('苹果', 24),
40
+ ('奚梦瑶', 20),
41
+ ('美国', 16),
42
+ ('特朗普', 16),
43
+ ('何猷君', 15),
44
+ ('戛纳', 13),
45
+ ('红毯', 12),
46
+ ('iPhone', 12),
47
+ ('车队', 9),
48
+ ('车祸', 9),
49
+ ('优衣', 9),
50
+ ('信息', 9),
51
+ ('李亚鹏', 9),
52
+ ('恋情', 9),
53
+ ('任素', 9),
54
+ ('男孩', 9),
55
+ ('亚洲', 8),
56
+ ('孩子', 8),
57
+ ('大学生', 8)]
58
+ shapes = ['circle', 'cardioid', 'diamond', 'triangle-forward', 'triangle', 'pentagon', 'star']
59
+
60
+ wc = (
61
+ WordCloud()
62
+ .add("WordCloud", data_pair=pairs, shape=shapes[0], width='900px', height='500px')
63
+
64
+ .set_global_opts(
65
+ title_opts=opts.TitleOpts(
66
+ title="WordCloud", subtitle="WordCloud"
67
+ ),
68
+ toolbox_opts=opts.ToolboxOpts(), )
69
+ )
70
+
71
+ st_pyecharts(wc)
72
+
73
+
pages/997_streamlit_aggrid.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 997_streamlit_aggrid
5
+ # @Time : 2022/10/17 下午1:14
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ from st_aggrid import AgGrid
13
+ import pandas as pd
14
+
15
+ df = pd.read_csv('./data/airline-safety.csv')
16
+ AgGrid(df)
17
+
18
+ # from st_aggrid import AgGrid, DataReturnMode, GridUpdateMode, GridOptionsBuilder
19
+ # options_builder = GridOptionsBuilder.from_dataframe(df)
20
+ # options_builder.configure_default_column(groupable=True, value=True, enableRowGroup=True, aggFunc='sum', editable=True, wrapText=True, autoHeight=True)
21
+ # options_builder.configure_column('col1', pinned='left')
22
+ # options_builder.configure_column('col2', pinned='left')
23
+ # grid_options = options_builder.build()
24
+ # grid_return = AgGrid(df, grid_options, theme='blue')
pages/998_streamlit_agraph.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_agraph import agraph, Node, Edge, Config
3
+
4
+
5
+ c1, c2 = st.columns(2)
6
+
7
+
8
+ with c1:
9
+
10
+ nodes = []
11
+ edges = []
12
+ nodes.append(Node(id="Spiderman",
13
+ label="Peter Parker",
14
+ size=25,
15
+ shape="circularImage",
16
+ image="http://marvel-force-chart.surge.sh/marvel_force_chart_img/top_spiderman.png")
17
+ ) # includes **kwargs
18
+ nodes.append(Node(id="Captain_Marvel",
19
+ size=25,
20
+ shape="circularImage",
21
+ image="http://marvel-force-chart.surge.sh/marvel_force_chart_img/top_captainmarvel.png")
22
+ )
23
+ edges.append(Edge(source="Captain_Marvel",
24
+ label="friend_of",
25
+ target="Spiderman",
26
+ # **kwargs
27
+ )
28
+ )
29
+
30
+ config = Config(width=500,
31
+ height=500,
32
+ # **kwargs
33
+ )
34
+
35
+ return_value = agraph(nodes=nodes, edges=edges, config=config)
36
+
37
+ with c2:
38
+ # Currently not workin since update to agraph 2.0 - work in progress
39
+ from rdflib import Graph
40
+ from streamlit_agraph import TripleStore, agraph
41
+
42
+ graph = Graph()
43
+ graph.parse("http://www.w3.org/People/Berners-Lee/card")
44
+ store = TripleStore()
45
+
46
+ for subj, pred, obj in graph:
47
+ store.add_triple(subj, pred, obj, "")
48
+
49
+ agraph(list(store.getNodes()), list(store.getEdges()), config)
pages/998_知识图谱.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from streamlit_agraph import agraph, Node, Edge, Config
3
+
4
+ from meutils.pipe import *
5
+
6
+ Node = lru_cache(100000)(Node)
7
+ Edge = lru_cache(100000)(Edge)
8
+
9
+
10
+ def df2nodes(df_nodes): # df.itertuples()
11
+ df_nodes.columns = ['k', 'v', 'r']
12
+
13
+ nodes = set()
14
+ edges = set()
15
+
16
+ for source, target, label in tqdm(df_nodes.values, 'Triplet'):
17
+ node_s = Node(source, label=source)
18
+ node_t = Node(target, label=target)
19
+
20
+ edge = Edge(source, target, label=label)
21
+
22
+ nodes.update([node_s, node_t])
23
+ edges.update([edge])
24
+ return nodes, edges
25
+
26
+
27
+ # df = pd.read_excel("~/Desktop/simple.xlsx", sheet_name="links")
28
+ df = pd.read_csv('~/Desktop/tt.csv').tail(500)
29
+
30
+
31
+ nodes, edges = df2nodes(df)
32
+
33
+ config = Config(width=1000, height=1000)
34
+
35
+
36
+ st.set_page_config(page_title="Knowledge Graph", page_icon="💗", layout="wide")
37
+ return_value = agraph(nodes=nodes, edges=edges, config=config)
38
+
39
+ del df, nodes, edges
pages/999_draw_table.py ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 999_draw_table
5
+ # @Time : 2022/10/17 下午1:36
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+
12
+ import streamlit as st
13
+ import pandas as pd
14
+ import streamlit.components.v1 as components
15
+
16
+ st.set_page_config(page_icon="🌴", page_title="Tabulator表格", layout="wide")
17
+
18
+ file = st.file_uploader("请上传文件", type=["csv"])
19
+
20
+ if file is not None:
21
+ df = pd.read_csv(file, encoding="gbk")
22
+
23
+
24
+ def draw_table(df, height, width):
25
+ columns = df.columns
26
+ column_selection = []
27
+ column_selection.append(
28
+ """<select id="filter-field" style="font-size:15px;background:white;color:black;border-radius:15%;border-color:grey;">""")
29
+ for i in range(len(columns)):
30
+ column_selection.append(
31
+ """<option value='""" + str(columns[i]) + """'>""" + str(columns[i]) + """</option>""")
32
+ column_selection.append("""</select>""")
33
+ table_data = df.to_dict(orient="records")
34
+ column_setting = []
35
+ column_setting.append(
36
+ """{rowHandle:true, formatter:"handle", headerSort:false, frozen:true, width:30, minWidth:30}""")
37
+ for y in range(df.shape[1]):
38
+ column_setting.append(
39
+ {"title": columns[y], "field": columns[y], "width": 200, "sorter": "string", "hozAlign": "center",
40
+ "headerFilter": "input", "editor": "input"})
41
+
42
+ components.html("""
43
+ <!DOCTYPE html>
44
+ <html lang="en">
45
+ <head>
46
+ <meta charset="UTF-8">
47
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
48
+ <title>Tabulator Example</title>
49
+ <link href="https://unpkg.com/[email protected]/dist/css/tabulator_modern.min.css" rel="stylesheet">
50
+ <script type="text/javascript" src="https://unpkg.com/[email protected]/dist/js/tabulator.min.js"></script>
51
+ <script type="text/javascript" src="https://moment.github.io/luxon/global/luxon.min.js"></script>
52
+ <script type="text/javascript" src="https://oss.sheetjs.com/sheetjs/xlsx.full.min.js"></script>
53
+ </head><body>
54
+ <div style="margin-left:30%;">""" + "".join(column_selection) +
55
+ """<select id="filter-type" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">
56
+ <option value="like">like</option>
57
+ <option value="=">=</option>
58
+ <option value="<"><</option>
59
+ <option value="<="><=</option>
60
+ <option value=">">></option>
61
+ <option value=">=">>=</option>
62
+ <option value="!=">!=</option>
63
+ </select>
64
+ <input id="filter-value" type="text" placeholder="填写要筛选的内容" style="font-size:15px;border-color:grey;border-radius:5%">
65
+ <button id="filter-clear" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">清除筛选</button>
66
+ <button id="download-csv" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">下载CSV</button>
67
+ <button id="download-xlsx" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">下载XLSX</button>
68
+ <button id="download-html" style="font-size:15px;background:#00ccff;color:white;border-radius:15%;border-color:white;">下载HTML</button>
69
+ </div><script type="text/javascript">
70
+ var fieldEl = document.getElementById("filter-field");
71
+ var typeEl = document.getElementById("filter-type");
72
+ var valueEl = document.getElementById("filter-value");
73
+ function customFilter(data){
74
+ return data.car && data.rating < 3;
75
+ }function updateFilter(){
76
+ var filterVal = fieldEl.options[fieldEl.selectedIndex].value;
77
+ var typeVal = typeEl.options[typeEl.selectedIndex].value;
78
+ var filter = filterVal == "function" ? customFilter : filterVal;
79
+ if(filterVal == "function" ){
80
+ typeEl.disabled = true;
81
+ valueEl.disabled = true;
82
+ }else{
83
+ typeEl.disabled = false;
84
+ valueEl.disabled = false;
85
+ }
86
+ if(filterVal){
87
+ table.setFilter(filter,typeVal, valueEl.value);
88
+ }
89
+ }
90
+ document.getElementById("filter-field").addEventListener("change", updateFilter);
91
+ document.getElementById("filter-type").addEventListener("change", updateFilter);
92
+ document.getElementById("filter-value").addEventListener("keyup", updateFilter);
93
+ document.getElementById("filter-clear").addEventListener("click", function(){
94
+ fieldEl.value = "";
95
+ typeEl.value = "=";
96
+ valueEl.value = "";
97
+ table.clearFilter();
98
+ });
99
+ </script>
100
+ <script type="text/javascript">
101
+ var table = new Tabulator("#example-table", {
102
+ ajaxURL:"http://www.getmydata.com/now",
103
+ });
104
+ document.getElementById("download-csv").addEventListener("click", function(){
105
+ table.download("csv", "data.csv");
106
+ });
107
+ document.getElementById("download-xlsx").addEventListener("click", function(){
108
+ table.download("xlsx", "data.xlsx", {sheetName:"My Data"});
109
+ });
110
+ document.getElementById("download-html").addEventListener("click", function(){
111
+ table.download("html", "data.html", {style:true});
112
+ });
113
+ </script><div id="players" style="margin-left:16%;"></div>""" +
114
+ """<script type="text/javascript">
115
+ var tabledata = [""" + ','.join(list(map(str, table_data))) + """];""" +
116
+ """var table = new Tabulator("#players", {
117
+ height: 320,
118
+ data: tabledata,
119
+ layout: "fitDataTable",
120
+ movableRows:true,
121
+ resizableColumnFit:true,
122
+ pagination: "local",
123
+ paginationSize: 5,
124
+ tooltips: true,
125
+ columns: [""" + ','.join(list(map(str, column_setting))) + """],});</script></body></html>""",
126
+ height=height, width=width)
127
+
128
+
129
+ draw_table(df, 500, 1200)
pages/__init__.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : AI. @by PyCharm
4
+ # @File : __init__.py
5
+ # @Time : 2023/3/26 19:23
6
+ # @Author : betterme
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+ from meutils.pipe import *
pages/chart.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import graphviz as graphviz
3
+
4
+ # Create a graphlib graph object
5
+ graph = graphviz.Digraph()
6
+ graph.edge('run', 'intr')
7
+ graph.edge('intr', 'runbl')
8
+ graph.edge('runbl', 'run')
9
+ graph.edge('run', 'kernel')
10
+ graph.edge('kernel', 'zombie')
11
+ graph.edge('kernel', 'sleep')
12
+ graph.edge('kernel', 'runmem')
13
+ graph.edge('sleep', 'swap')
14
+ graph.edge('swap', 'runswap')
15
+ graph.edge('runswap', 'new')
16
+ graph.edge('runswap', 'runmem')
17
+ graph.edge('new', 'runmem')
18
+ graph.edge('sleep', 'runmem')
19
+
20
+ st.graphviz_chart(graph)
pages/demo-aggrid-width-center.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ from st_aggrid import AgGrid
4
+ # from st_aggrid.grid_options_builder import GridOptionsBuilder
5
+ # from st_aggrid.shared import JsCode
6
+ # from st_aggrid.shared import GridUpdateMode
7
+
8
+ num=range(1,10)
9
+ data=pd.DataFrame({'A':num,'B':num,'C':num})
10
+
11
+ gridOptions = {
12
+ "columnDefs": [
13
+ {'headerName':'A列',"field": 'A','width':80,'cellStyle':{'color':'red','textAlign': 'center','font-weight':'bold'}},
14
+ #此外还可以设置minWidth 与maxWidth来控制宽度
15
+ {'headerName':'B列',"field": 'B','width':144,'cellStyle':{'color':'red','textAlign': 'center','font-weight':'bold'}},
16
+ {'headerName':'C列',"field": 'C','width':80,'cellStyle':{'color':'red','textAlign': 'center','font-weight':'bold'}}
17
+ ],
18
+ "defaultColDef": {
19
+ "sortable": True,
20
+ "filter": False,
21
+ # "width":200 #可以设置各行的默认值
22
+ },
23
+ }
24
+
25
+
26
+ data_ag = AgGrid(data, # 数据
27
+ gridOptions=gridOptions, # 布局选项
28
+ # fit_columns_on_grid_load=True, #此参数会以列宽为比例自动铺满表格
29
+ allow_unsafe_jscode=True,
30
+ key=1,
31
+ custom_css={'.ag-header-cell-text':{'flex':'1','text-align':'center'}}) #此处是设置列名居中
32
+
33
+ #可配合st.columns来设置表格的整体宽度
34
+ c1,c2=st.columns(2)
35
+ with c1:
36
+ AgGrid(data, # 数据
37
+ gridOptions=gridOptions, # 布局选项
38
+ allow_unsafe_jscode=True,
39
+ key=2,
40
+ custom_css={'.ag-header-cell-text': {'flex': '1', 'text-align': 'center'}})
41
+
42
+ #铺满表格
43
+ c1,c2=st.columns(2)
44
+ with c1:
45
+ AgGrid(data, # 数据
46
+ gridOptions=gridOptions, # 布局选项
47
+ allow_unsafe_jscode=True,
48
+ fit_columns_on_grid_load=True,
49
+ key=3,
50
+ custom_css={'.ag-header-cell-text': {'flex': '1', 'text-align': 'center'}})
51
+
52
+ #铺满且居中
53
+ c1,c2,c3=st.columns([1,2,1])
54
+ with c2:
55
+ AgGrid(data, # 数据
56
+ gridOptions=gridOptions, # 布局选项
57
+ allow_unsafe_jscode=True,
58
+ fit_columns_on_grid_load=True,
59
+ key=4,
60
+ custom_css={'.ag-header-cell-text': {'flex': '1', 'text-align': 'center'}})
61
+
62
+
63
+
64
+
pages/iframe.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : AI. @by PyCharm
4
+ # @File : iframe
5
+ # @Time : 2023/4/6 11:43
6
+ # @Author : betterme
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+ from meutils.pipe import *
12
+
13
+ html = """
14
+ <!DOCTYPE html>
15
+ <html>
16
+ <head>
17
+ <title>My Website</title>
18
+ <style>
19
+ iframe {
20
+ width: 100%;
21
+ height: 100%;
22
+ border: none;
23
+ overflow: hidden;
24
+ }
25
+ </style>
26
+ </head>
27
+ <body>
28
+ <iframe src="http://www.hao123.com/"></iframe>
29
+ </body>
30
+ </html>
31
+ """
32
+
33
+ import streamlit as st
34
+
35
+
36
+ st.write(html, unsafe_allow_html=True)
pages/xxxx.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : xxxx
5
+ # @Time : 2022/12/7 上午9:04
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
pages/多轮对话.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : Python.
4
+ # @File : 991_streamlit_apex_charts
5
+ # @Time : 2022/10/17 上午10:48
6
+ # @Author : yuanjie
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+ import streamlit as st
11
+ from streamlit_chat import message
12
+
13
+
14
+ def reply(input, history=None, reply_func=lambda input: f'{input}的答案', max_turns=3, container=None):
15
+ if history is None:
16
+ history = [] # [(query, response)]
17
+
18
+ if container is None:
19
+ container = st.container()
20
+
21
+ with container:
22
+ if len(history) > 0:
23
+ for i, (query, response) in enumerate(history[-max_turns + 1:]):
24
+ message(query, avatar_style="big-smile", is_user=True, key=str(i) + "_user")
25
+ message(response, avatar_style="bottts", is_user=False, key=str(i))
26
+
27
+ message(input, avatar_style="big-smile", is_user=True, key=str(len(history)) + "_user")
28
+ # st.write("AI正在回复:")
29
+ with st.empty():
30
+ response = reply_func(input)
31
+ message(response, avatar_style="bottts", is_user=False)
32
+
33
+ history.append((input, response))
34
+ return history
35
+
36
+
37
+ if __name__ == '__main__':
38
+ def display_previous_message(texts=None):
39
+ if texts:
40
+ for msg in texts:
41
+ message(msg, avatar_style="bottts") # display all the previous message
42
+
43
+
44
+ display_previous_message(["你好!我是你的电影小助手,很高兴为您服务。", "你可以向我提问。"])
45
+
46
+ container = st.container() # 占位符
47
+ text = st.text_area(label="用户输入", height=100, placeholder="请在这儿输入您的问题")
48
+
49
+ if st.button("发送", key="predict"):
50
+ with st.spinner("AI正在思考,请稍等........"):
51
+ history = st.session_state.get('state')
52
+ st.session_state["state"] = reply(text, history, container=container)
53
+ print(st.session_state['state'])
pages/弹窗.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # @Project : AI. @by PyCharm
4
+ # @File : 弹窗
5
+ # @Time : 2023/4/2 12:35
6
+ # @Author : betterme
7
+ # @WeChat : meutils
8
+ # @Software : PyCharm
9
+ # @Description :
10
+
11
+ from meutils.pipe import *
12
+ import streamlit as st
13
+ from streamlit_modal import Modal
14
+
15
+ import streamlit.components.v1 as components
16
+
17
+ modal = Modal("Demo Modal", key='k')
18
+ open_modal = st.button("Open")
19
+ if open_modal:
20
+ modal.open()
21
+
22
+ if modal.is_open():
23
+ with modal.container():
24
+ st.write("Text goes here")
25
+
26
+ html_string = '''
27
+ <h1>HTML string in RED</h1>
28
+
29
+ <script language="javascript">
30
+ document.querySelector("h1").style.color = "red";
31
+ </script>
32
+ '''
33
+ components.html(html_string)
34
+
35
+ st.write("Some fancy text")
36
+ value = st.checkbox("Check me")
37
+ st.write(f"Checkbox checked: {value}")
38
+
39
+ #
40
+ # from transformers import AutoModelForQuestionAnswering,AutoTokenizer,pipeline
41
+ # model = AutoModelForQuestionAnswering.from_pretrained('uer/roberta-base-chinese-extractive-qa')
42
+ # tokenizer = AutoTokenizer.from_pretrained('uer/roberta-base-chinese-extractive-qa')
43
+ # QA = pipeline('question-answering', model=model, tokenizer=tokenizer)
44
+ # QA_input = {'question': "著名诗歌《假如生活欺骗了你》的作者是",'context': "普希金从那里学习人民的语言,吸取了许多有益的养料,这一切对普希金后来的创作产生了很大的影响。这两年里,普希金创作了不少优秀的作品,如《囚徒》、《致大海》、《致凯恩》和《假如生活欺骗了你》等几十首抒情诗,叙事诗《努林伯爵》,历史剧《鲍里斯·戈都诺夫》,以及《叶甫盖尼·奥涅金》前六章。"}
45
+ # QA(QA_input)
requirements.txt ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ meutils
2
+ appzoo
3
+ pyecharts
4
+ m2cgen
5
+ psutil
6
+ lac
7
+
8
+ # streamlit
9
+ streamlit=
10
+ streamlit_autorefresh
11
+ streamlit_chat
12
+ streamlit_text_rating
13
+ streamlit_echarts
14
+ streamlit-aggrid
15
+ streamlit-agraph
16
+ st-annotated-text
17
+ streamlit-tree-select
18
+ streamlit_pandas_profiling
19
+ streamlit_authenticator
20
+ streamlit_option_menu
21
+ streamlit_ace
run.sh ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # @Project : nesc
3
+ # @Time : 2022/9/21 下午5:20
4
+ # @Author : yuanjie
5
+ # @Email : [email protected]
6
+ # @Software : PyCharm
7
+ # @Description : ${DESCRIPTION}
8
+
9
+ streamlit run _👋_.py --server.port 9955
10
+