Update app.py
Browse files
app.py
CHANGED
|
@@ -7,29 +7,29 @@ app = Flask(__name__)
|
|
| 7 |
FIG_DIR = "FIG"
|
| 8 |
ZIP_FILE = "FIG.zip"
|
| 9 |
|
| 10 |
-
# 自动解压 FIG.zip
|
| 11 |
if not os.path.exists(FIG_DIR):
|
| 12 |
if os.path.exists(ZIP_FILE):
|
| 13 |
with zipfile.ZipFile(ZIP_FILE, 'r') as zip_ref:
|
| 14 |
zip_ref.extractall(FIG_DIR)
|
| 15 |
-
print(
|
| 16 |
else:
|
| 17 |
-
print(
|
| 18 |
|
| 19 |
@app.route("/")
|
| 20 |
-
def
|
| 21 |
-
return "✅
|
| 22 |
|
| 23 |
@app.route("/extract")
|
| 24 |
def extract():
|
| 25 |
-
figures = []
|
| 26 |
base_url = "https://sferewqw--poster.hf.space/file/FIG"
|
|
|
|
| 27 |
|
| 28 |
if not os.path.exists(FIG_DIR):
|
| 29 |
-
return jsonify({"error": "FIG folder not found
|
| 30 |
|
| 31 |
for filename in os.listdir(FIG_DIR):
|
| 32 |
-
if filename.lower().endswith((".png", ".jpg", ".jpeg"
|
| 33 |
figures.append({
|
| 34 |
"filename": filename,
|
| 35 |
"url": f"{base_url}/{filename}",
|
|
@@ -40,3 +40,4 @@ def extract():
|
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
|
|
| 7 |
FIG_DIR = "FIG"
|
| 8 |
ZIP_FILE = "FIG.zip"
|
| 9 |
|
| 10 |
+
# 自动解压 FIG.zip(只解压一次)
|
| 11 |
if not os.path.exists(FIG_DIR):
|
| 12 |
if os.path.exists(ZIP_FILE):
|
| 13 |
with zipfile.ZipFile(ZIP_FILE, 'r') as zip_ref:
|
| 14 |
zip_ref.extractall(FIG_DIR)
|
| 15 |
+
print("✅ 解压 FIG.zip 成功")
|
| 16 |
else:
|
| 17 |
+
print("⚠️ FIG.zip 不存在,跳过解压")
|
| 18 |
|
| 19 |
@app.route("/")
|
| 20 |
+
def home():
|
| 21 |
+
return "✅ Service running. Try /extract"
|
| 22 |
|
| 23 |
@app.route("/extract")
|
| 24 |
def extract():
|
|
|
|
| 25 |
base_url = "https://sferewqw--poster.hf.space/file/FIG"
|
| 26 |
+
figures = []
|
| 27 |
|
| 28 |
if not os.path.exists(FIG_DIR):
|
| 29 |
+
return jsonify({"error": "FIG folder not found"}), 500
|
| 30 |
|
| 31 |
for filename in os.listdir(FIG_DIR):
|
| 32 |
+
if filename.lower().endswith((".png", ".jpg", ".jpeg")):
|
| 33 |
figures.append({
|
| 34 |
"filename": filename,
|
| 35 |
"url": f"{base_url}/{filename}",
|
|
|
|
| 40 |
|
| 41 |
if __name__ == "__main__":
|
| 42 |
app.run(host="0.0.0.0", port=7860)
|
| 43 |
+
|