Spaces:
Sleeping
Sleeping
Commit ·
19abb06
1
Parent(s): 912fe4d
fix: 解决Jinja与Vue冲突;新增健康检查与发布指南
Browse files- app.py +23 -0
- templates/index.html +2 -0
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import io
|
| 3 |
import zipfile
|
| 4 |
from flask import Flask, render_template, request, send_file, jsonify
|
|
|
|
| 5 |
from PIL import Image, ImageOps
|
| 6 |
|
| 7 |
app = Flask(__name__)
|
|
@@ -11,6 +12,10 @@ app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max upload
|
|
| 11 |
def index():
|
| 12 |
return render_template('index.html')
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@app.route('/api/split', methods=['POST'])
|
| 15 |
def split_image():
|
| 16 |
if 'file' not in request.files:
|
|
@@ -109,6 +114,20 @@ def split_image():
|
|
| 109 |
index = r * cols + c + 1
|
| 110 |
filename = f"tile_{index:02d}.{format.lower()}"
|
| 111 |
zf.writestr(filename, tile_bytes.read())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
memory_file.seek(0)
|
| 114 |
return send_file(
|
|
@@ -121,5 +140,9 @@ def split_image():
|
|
| 121 |
except Exception as e:
|
| 122 |
return jsonify({'error': str(e)}), 500
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
if __name__ == '__main__':
|
| 125 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 2 |
import io
|
| 3 |
import zipfile
|
| 4 |
from flask import Flask, render_template, request, send_file, jsonify
|
| 5 |
+
from werkzeug.exceptions import RequestEntityTooLarge
|
| 6 |
from PIL import Image, ImageOps
|
| 7 |
|
| 8 |
app = Flask(__name__)
|
|
|
|
| 12 |
def index():
|
| 13 |
return render_template('index.html')
|
| 14 |
|
| 15 |
+
@app.route('/api/health')
|
| 16 |
+
def health():
|
| 17 |
+
return jsonify({'status': 'ok'}), 200
|
| 18 |
+
|
| 19 |
@app.route('/api/split', methods=['POST'])
|
| 20 |
def split_image():
|
| 21 |
if 'file' not in request.files:
|
|
|
|
| 114 |
index = r * cols + c + 1
|
| 115 |
filename = f"tile_{index:02d}.{format.lower()}"
|
| 116 |
zf.writestr(filename, tile_bytes.read())
|
| 117 |
+
|
| 118 |
+
# Add posting order guide
|
| 119 |
+
order_lines = []
|
| 120 |
+
order_lines.append(f"发布顺序指南({rows}x{cols})")
|
| 121 |
+
order_lines.append("从左到右,从上到下:")
|
| 122 |
+
nums = [f"{i:02d}" for i in range(1, rows * cols + 1)]
|
| 123 |
+
for r in range(rows):
|
| 124 |
+
row_slice = nums[r * cols:(r + 1) * cols]
|
| 125 |
+
order_lines.append(" " + " ".join(row_slice))
|
| 126 |
+
order_lines.append("")
|
| 127 |
+
order_lines.append("建议:")
|
| 128 |
+
order_lines.append("1. 朋友圈/小红书九宫格:按上述顺序依次选择图片。")
|
| 129 |
+
order_lines.append("2. 若平台有排序规则,请关闭自动排序或手动调整。")
|
| 130 |
+
zf.writestr("posting_order.txt", "\n".join(order_lines))
|
| 131 |
|
| 132 |
memory_file.seek(0)
|
| 133 |
return send_file(
|
|
|
|
| 140 |
except Exception as e:
|
| 141 |
return jsonify({'error': str(e)}), 500
|
| 142 |
|
| 143 |
+
@app.errorhandler(RequestEntityTooLarge)
|
| 144 |
+
def handle_file_too_large(e):
|
| 145 |
+
return jsonify({'error': '文件过大,超过限制(最大16MB)'}), 413
|
| 146 |
+
|
| 147 |
if __name__ == '__main__':
|
| 148 |
app.run(host='0.0.0.0', port=7860)
|
templates/index.html
CHANGED
|
@@ -38,6 +38,7 @@
|
|
| 38 |
</style>
|
| 39 |
</head>
|
| 40 |
<body class="bg-gray-50 text-gray-800 min-h-screen flex flex-col">
|
|
|
|
| 41 |
<div id="app" v-cloak class="flex-grow container mx-auto px-4 py-8 max-w-4xl">
|
| 42 |
<!-- Header -->
|
| 43 |
<header class="text-center mb-10">
|
|
@@ -203,5 +204,6 @@
|
|
| 203 |
</div>
|
| 204 |
|
| 205 |
<script src="/static/js/app.js"></script>
|
|
|
|
| 206 |
</body>
|
| 207 |
</html>
|
|
|
|
| 38 |
</style>
|
| 39 |
</head>
|
| 40 |
<body class="bg-gray-50 text-gray-800 min-h-screen flex flex-col">
|
| 41 |
+
{% raw %}
|
| 42 |
<div id="app" v-cloak class="flex-grow container mx-auto px-4 py-8 max-w-4xl">
|
| 43 |
<!-- Header -->
|
| 44 |
<header class="text-center mb-10">
|
|
|
|
| 204 |
</div>
|
| 205 |
|
| 206 |
<script src="/static/js/app.js"></script>
|
| 207 |
+
{% endraw %}
|
| 208 |
</body>
|
| 209 |
</html>
|