duqing2026 commited on
Commit
e8ebb5d
·
1 Parent(s): 3557c8f

升级优化

Browse files
Files changed (5) hide show
  1. Dockerfile +4 -3
  2. README.md +9 -5
  3. app.py +17 -3
  4. requirements.txt +2 -0
  5. templates/index.html +12 -1
Dockerfile CHANGED
@@ -3,7 +3,8 @@ FROM python:3.9-slim
3
  WORKDIR /app
4
 
5
  # Install dependencies
6
- RUN pip install flask
 
7
 
8
  # Copy application files
9
  COPY . .
@@ -15,5 +16,5 @@ USER user
15
  # Expose the port (Hugging Face Spaces uses 7860)
16
  EXPOSE 7860
17
 
18
- # Run the application
19
- CMD ["python", "app.py"]
 
3
  WORKDIR /app
4
 
5
  # Install dependencies
6
+ COPY requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
 
9
  # Copy application files
10
  COPY . .
 
16
  # Expose the port (Hugging Face Spaces uses 7860)
17
  EXPOSE 7860
18
 
19
+ # Run the application with Gunicorn
20
+ CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app"]
README.md CHANGED
@@ -19,11 +19,11 @@ short_description: ZenFlow - 禅意专注流
19
  - **极简设计**:深色模式 UI,呼吸灯视觉引导,无干扰。
20
  - **番茄钟**:内置 25 分钟专注 / 5 分钟休息循环,带有柔和的提示音。
21
  - **沉浸体验**:支持全屏模式,隐藏所有多余元素。
22
- - **单任务流**:一次只专注于一件事,提供输入框记录当前任务。
23
 
24
  ## 🛠️ 技术栈
25
 
26
- - **后端**:Flask (Python) - 极简静态文件服务
27
  - **前端**:Vue 3 (Composition API) + Tailwind CSS
28
  - **音频**:Web Audio API (ScriptProcessor/BufferSource)
29
  - **部署**:Docker + Hugging Face Spaces
@@ -32,15 +32,19 @@ short_description: ZenFlow - 禅意专注流
32
 
33
  ### 本地运行
34
 
35
- 1. 安装依赖(其实只需要 Flask)
36
  ```bash
37
- pip install flask
38
  ```
39
 
40
- 2. 运行应用:
41
  ```bash
42
  python app.py
43
  ```
 
 
 
 
44
 
45
  3. 访问 `http://localhost:7860`
46
 
 
19
  - **极简设计**:深色模式 UI,呼吸灯视觉引导,无干扰。
20
  - **番茄钟**:内置 25 分钟专注 / 5 分钟休息循环,带有柔和的提示音。
21
  - **沉浸体验**:支持全屏模式,隐藏所有多余元素。
22
+ - **单任务流**:一次只专注于一件事,提供输入框记录当前任务,并提供智能预设任务建议
23
 
24
  ## 🛠️ 技术栈
25
 
26
+ - **后端**:Flask (Python) + Gunicorn - 生产级 Web 服务
27
  - **前端**:Vue 3 (Composition API) + Tailwind CSS
28
  - **音频**:Web Audio API (ScriptProcessor/BufferSource)
29
  - **部署**:Docker + Hugging Face Spaces
 
32
 
33
  ### 本地运行
34
 
35
+ 1. 安装依赖:
36
  ```bash
37
+ pip install -r requirements.txt
38
  ```
39
 
40
+ 2. 运行应用(开发模式)
41
  ```bash
42
  python app.py
43
  ```
44
+ 或者使用 Gunicorn(生产模式,推荐):
45
+ ```bash
46
+ gunicorn -b 0.0.0.0:7860 app:app
47
+ ```
48
 
49
  3. 访问 `http://localhost:7860`
50
 
app.py CHANGED
@@ -1,5 +1,10 @@
1
- from flask import Flask, render_template, send_from_directory
2
  import os
 
 
 
 
 
3
 
4
  app = Flask(__name__)
5
 
@@ -9,11 +14,20 @@ app.jinja_env.variable_end_string = ']]'
9
 
10
  @app.route('/')
11
  def index():
12
- return render_template('index.html')
 
 
 
 
 
 
 
 
13
 
14
  @app.route('/static/<path:path>')
15
  def send_static(path):
16
  return send_from_directory('static', path)
17
 
18
  if __name__ == '__main__':
19
- app.run(host='0.0.0.0', port=7860)
 
 
1
+ import logging
2
  import os
3
+ from flask import Flask, render_template, send_from_directory, jsonify
4
+
5
+ # Configure logging
6
+ logging.basicConfig(level=logging.INFO)
7
+ logger = logging.getLogger(__name__)
8
 
9
  app = Flask(__name__)
10
 
 
14
 
15
  @app.route('/')
16
  def index():
17
+ try:
18
+ return render_template('index.html')
19
+ except Exception as e:
20
+ logger.error(f"Error rendering index: {e}")
21
+ return "Internal Server Error", 500
22
+
23
+ @app.route('/health')
24
+ def health():
25
+ return jsonify({"status": "healthy"})
26
 
27
  @app.route('/static/<path:path>')
28
  def send_static(path):
29
  return send_from_directory('static', path)
30
 
31
  if __name__ == '__main__':
32
+ port = int(os.environ.get('PORT', 7860))
33
+ app.run(host='0.0.0.0', port=port)
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ flask>=2.0.0
2
+ gunicorn>=20.1.0
templates/index.html CHANGED
@@ -4,6 +4,7 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>ZenFlow - 禅意专注流</title>
 
7
  <script src="https://cdn.tailwindcss.com"></script>
8
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
9
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
@@ -282,6 +283,15 @@
282
  const showControls = ref(true);
283
  const isFullscreen = ref(false);
284
  const currentTask = ref('');
 
 
 
 
 
 
 
 
 
285
 
286
  const noiseTypes = [
287
  { id: 'pink', name: '粉红噪音 (雨声)', icon: 'fas fa-cloud-rain' },
@@ -459,7 +469,8 @@
459
  // UI
460
  showControls,
461
  isFullscreen,
462
- toggleFullscreen
 
463
  };
464
  }
465
  }).mount('#app');
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>ZenFlow - 禅意专注流</title>
7
+ <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🧘</text></svg>">
8
  <script src="https://cdn.tailwindcss.com"></script>
9
  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
10
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
 
283
  const showControls = ref(true);
284
  const isFullscreen = ref(false);
285
  const currentTask = ref('');
286
+
287
+ // Default Data / Suggested Tasks
288
+ const suggestedTasks = [
289
+ '深度阅读 25 分钟',
290
+ '完成代码重构',
291
+ '撰写项目文档',
292
+ '冥想休息',
293
+ '整理今日待办'
294
+ ];
295
 
296
  const noiseTypes = [
297
  { id: 'pink', name: '粉红噪音 (雨声)', icon: 'fas fa-cloud-rain' },
 
469
  // UI
470
  showControls,
471
  isFullscreen,
472
+ toggleFullscreen,
473
+ suggestedTasks
474
  };
475
  }
476
  }).mount('#app');