Qilan2 commited on
Commit
c9395f7
·
verified ·
1 Parent(s): 2f8ae95

Update sbx/b.py

Browse files
Files changed (1) hide show
  1. sbx/b.py +130 -106
sbx/b.py CHANGED
@@ -17,6 +17,7 @@ HF_USER1 = os.environ.get('HF_USER1', '')# HF 备份仓库的用户名
17
  HF_REPO = os.environ.get('HF_REPO', '')#HF 备份的Models仓库名
18
  HF_EMAIL = os.environ.get('HF_EMAIL', '') #HF的邮箱
19
  HF_TOKEN1 = os.environ.get('HF_TOKEN1', '')#HF备份账号的TOKEN
 
20
  def jupyter():
21
  os.system('jupyter lab --ip=0.0.0.0 --port=8002 --no-browser --allow-root --notebook-dir=/data --NotebookApp.token=qilan --ServerApp.disable_check_xsrf=True')
22
 
@@ -33,138 +34,161 @@ HTML_PAGE = """
33
  <title>Flask 应用</title>
34
  <style>
35
  body {
36
- font-family: Arial, sans-serif;
37
- max-width: 800px;
38
  margin: 0 auto;
39
  padding: 20px;
40
- background-color: #f5f5f5;
 
41
  }
42
  .container {
43
  background: white;
44
- padding: 30px;
45
- border-radius: 10px;
46
- box-shadow: 0 2px 10px rgba(0,0,0,0.1);
47
  }
48
  h1 {
49
  color: #333;
50
  text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
  .link {
53
  display: inline-block;
54
- margin: 10px;
55
- padding: 10px 20px;
56
- background: #007bff;
57
  color: white;
58
  text-decoration: none;
59
- border-radius: 5px;
 
 
60
  }
61
  .link:hover {
62
- background: #0056b3;
 
 
 
 
 
 
63
  }
64
  </style>
65
  </head>
66
  <body>
67
  <div class="container">
68
  <h1>🚀 Flask 应用主页</h1>
69
- <p>欢迎来到 Flask 应用!这是一个简单的 HTML 页面。</p>
70
- <p>您可以访问以下端点:</p>
71
- <a href="/hello" class="link">/hello - JSON API</a>
72
- <a href="/" class="link">/ - 主页</a>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  </body>
75
  </html>
76
  """
77
- def compress_folder(folder_path, output_dir):
78
- try:
79
- # 确保输出目录存在
80
- os.makedirs(output_dir, exist_ok=True)
81
-
82
- # 使用 pytz 获取中国时区的当前时间戳(毫秒级)
83
- import pytz
84
- from datetime import datetime
85
-
86
- # 设置中国时区
87
- china_tz = pytz.timezone('Asia/Shanghai')
88
-
89
- # 获取当前中国时间的时间戳
90
- timestamp = str(int(datetime.now(china_tz).timestamp() * 1000))
91
- output_path = os.path.join(output_dir, f'{timestamp}.tar.gz')
92
-
93
- # 获取已存在的压缩包
94
- existing_archives = glob.glob(os.path.join(output_dir, '*.tar.gz'))
95
-
96
- # 安全地提取时间戳
97
- def extract_timestamp(filename):
98
- # 提取文件名中的数字部分
99
- match = re.search(r'(\d+)\.tar\.gz$', filename)
100
- return int(match.group(1)) if match else 0
101
-
102
- # 如果压缩包数量超过5个,删除最旧的
103
- if len(existing_archives) >= 5:
104
- # 按时间戳排序
105
- existing_archives.sort(key=extract_timestamp)
106
-
107
- # 删除最旧的压缩包
108
- oldest_archive = existing_archives[0]
109
- os.remove(oldest_archive)
110
- print(f"删除最旧的压缩包:{oldest_archive}")
111
-
112
- # tar.gz 压缩
113
- result = subprocess.run(
114
- ['tar', '-czvf', output_path, folder_path],
115
- capture_output=True,
116
- text=True
117
- )
118
-
119
- if result.returncode == 0:
120
- # 计算压缩包大小
121
- file_size = os.path.getsize(output_path) / 1024 / 1024
122
-
123
- # 格式化中国时区的时间
124
- china_time = datetime.now(china_tz)
125
- formatted_time = china_time.strftime('%Y-%m-%d %H:%M:%S')
126
-
127
- print(f"压缩成功:{output_path}")
128
- print(f"压缩大小:{file_size:.2f} MB")
129
- print(f"压缩时间:{formatted_time}")
130
-
131
- # 返回压缩包名和大小信息
132
- return f"{os.path.basename(output_path)} MB:{file_size:.2f} MB TIME:{formatted_time}"
133
- else:
134
- print("压缩失败")
135
- print("错误信息:", result.stderr)
136
- return None
137
-
138
- except Exception as e:
139
- print(f"压缩出错: {e}")
140
- return None
141
- def github(type):
142
- if type == 1:
143
- os.system(f'rm -rf /data/{HF_REPO}')
144
- if not os.path.exists(f'/data/{HF_REPO}'):
145
- git = f"git clone https://{HF_USER1}:{HF_TOKEN1}@huggingface.co/{HF_USER1}/{HF_REPO}"
146
- print(git)
147
- os.system(git)
148
- os.system(f'git config --global user.email "{HF_EMAIL}"')
149
- os.system(f'git config --global user.name "{HF_USER1}"')
150
- os.chdir(f'/data/{HF_REPO}')
151
- if type == 2:
152
- os.chdir(f'/data/{HF_REPO}')
153
- print("开始备份上传HF")
154
- # 清理 LFS 存储
155
- os.system('git lfs prune')
156
- # 备份上传仓库
157
- new_archive_info = compress_folder('/data/dv1', f'/data/{HF_REPO}')
158
- if new_archive_info:
159
- new_archive, file_size_info = new_archive_info.split(' MB:')
160
- os.system(f'git add .')
161
- os.system(f'git commit -m "{file_size_info}"')
162
- # os.system('git push -u origin main')
163
- # 使用强制推送并清理
164
- os.system('git push -f origin main')
165
- os.system('git gc --prune=now')
166
- else:
167
- print("压缩失败,无法提交")
168
  @app.route('/')
169
  def index():
170
  """根路由,返回 HTML 页面"""
 
17
  HF_REPO = os.environ.get('HF_REPO', '')#HF 备份的Models仓库名
18
  HF_EMAIL = os.environ.get('HF_EMAIL', '') #HF的邮箱
19
  HF_TOKEN1 = os.environ.get('HF_TOKEN1', '')#HF备份账号的TOKEN
20
+
21
  def jupyter():
22
  os.system('jupyter lab --ip=0.0.0.0 --port=8002 --no-browser --allow-root --notebook-dir=/data --NotebookApp.token=qilan --ServerApp.disable_check_xsrf=True')
23
 
 
34
  <title>Flask 应用</title>
35
  <style>
36
  body {
37
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
38
+ max-width: 1000px;
39
  margin: 0 auto;
40
  padding: 20px;
41
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
42
+ min-height: 100vh;
43
  }
44
  .container {
45
  background: white;
46
+ padding: 40px;
47
+ border-radius: 15px;
48
+ box-shadow: 0 10px 40px rgba(0,0,0,0.2);
49
  }
50
  h1 {
51
  color: #333;
52
  text-align: center;
53
+ margin-bottom: 30px;
54
+ font-size: 2.5em;
55
+ }
56
+ .info-section {
57
+ background: #f8f9fa;
58
+ padding: 20px;
59
+ border-radius: 10px;
60
+ margin: 20px 0;
61
+ border-left: 4px solid #667eea;
62
+ }
63
+ .time-display {
64
+ font-size: 1.2em;
65
+ color: #667eea;
66
+ font-weight: bold;
67
+ margin: 10px 0;
68
+ }
69
+ .hitokoto-container {
70
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
71
+ color: white;
72
+ padding: 30px;
73
+ border-radius: 10px;
74
+ margin: 20px 0;
75
+ text-align: center;
76
+ min-height: 120px;
77
+ display: flex;
78
+ flex-direction: column;
79
+ justify-content: center;
80
+ box-shadow: 0 5px 20px rgba(102, 126, 234, 0.3);
81
+ }
82
+ .hitokoto-text {
83
+ font-size: 1.3em;
84
+ font-style: italic;
85
+ margin-bottom: 15px;
86
+ line-height: 1.6;
87
+ }
88
+ .hitokoto-from {
89
+ font-size: 0.95em;
90
+ opacity: 0.9;
91
+ margin-top: 10px;
92
+ }
93
+ .links-container {
94
+ display: flex;
95
+ flex-wrap: wrap;
96
+ justify-content: center;
97
+ gap: 15px;
98
+ margin-top: 30px;
99
  }
100
  .link {
101
  display: inline-block;
102
+ padding: 12px 24px;
103
+ background: #667eea;
 
104
  color: white;
105
  text-decoration: none;
106
+ border-radius: 8px;
107
+ transition: all 0.3s ease;
108
+ font-weight: 500;
109
  }
110
  .link:hover {
111
+ background: #764ba2;
112
+ transform: translateY(-2px);
113
+ box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
114
+ }
115
+ .loading {
116
+ color: #999;
117
+ font-style: italic;
118
  }
119
  </style>
120
  </head>
121
  <body>
122
  <div class="container">
123
  <h1>🚀 Flask 应用主页</h1>
124
+
125
+ <div class="info-section">
126
+ <h2 style="color: #333; margin-top: 0;">📅 当前时间</h2>
127
+ <div class="time-display" id="current-time">加载中...</div>
128
+ <p style="color: #666; margin: 10px 0 0 0;">时区:亚洲/上海</p>
129
+ </div>
130
+
131
+ <div class="hitokoto-container">
132
+ <div class="hitokoto-text" id="hitokoto">:D 获取一言中...</div>
133
+ <div class="hitokoto-from" id="hitokoto-from"></div>
134
+ </div>
135
+
136
+ <div class="info-section">
137
+ <h2 style="color: #333; margin-top: 0;">🔗 API 端点</h2>
138
+ <p>您可以访问以下端点:</p>
139
+ <div class="links-container">
140
+ <a href="/hello" class="link">/hello - JSON API</a>
141
+ <a href="/xx" class="link">/xx - 系统信息</a>
142
+ <a href="/" class="link">/ - 主页</a>
143
+ </div>
144
+ </div>
145
  </div>
146
+
147
+ <script>
148
+ // 更新时间
149
+ function updateTime() {
150
+ const now = new Date();
151
+ const options = {
152
+ year: 'numeric',
153
+ month: '2-digit',
154
+ day: '2-digit',
155
+ hour: '2-digit',
156
+ minute: '2-digit',
157
+ second: '2-digit',
158
+ hour12: false
159
+ };
160
+ const timeString = now.toLocaleString('zh-CN', options);
161
+ document.getElementById('current-time').textContent = timeString;
162
+ }
163
+
164
+ // 获取一言
165
+ function fetchHitokoto() {
166
+ fetch('https://v1.hitokoto.cn?encode=json')
167
+ .then(response => response.json())
168
+ .then(data => {
169
+ document.getElementById('hitokoto').textContent = data.hitokoto;
170
+ document.getElementById('hitokoto-from').textContent = '——' + (data.from_who ? data.from_who + '《' + data.from + '》' : data.from);
171
+ })
172
+ .catch(error => {
173
+ console.log('获取一言失败:', error);
174
+ document.getElementById('hitokoto').textContent = '每一个不曾起舞的日子,都是对生命的辜负。';
175
+ document.getElementById('hitokoto-from').textContent = '——尼采';
176
+ });
177
+ }
178
+
179
+ // 初始化
180
+ updateTime();
181
+ fetchHitokoto();
182
+
183
+ // 每秒更新时间
184
+ setInterval(updateTime, 1000);
185
+
186
+ // 每60秒刷新一言
187
+ setInterval(fetchHitokoto, 60000);
188
+ </script>
189
  </body>
190
  </html>
191
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  @app.route('/')
193
  def index():
194
  """根路由,返回 HTML 页面"""