SFEREWQW commited on
Commit
5fa362b
·
verified ·
1 Parent(s): 70e2cd6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
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(f"✅ 解压 {ZIP_FILE} 成功,生成 {FIG_DIR}/ 文件夹")
16
  else:
17
- print(f"⚠️ {ZIP_FILE} 不存在,无法解压图像目录")
18
 
19
  @app.route("/")
20
- def index():
21
- return "✅ Figure extraction service is running. Visit <code>/extract</code> to get JSON."
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."}), 500
30
 
31
  for filename in os.listdir(FIG_DIR):
32
- if filename.lower().endswith((".png", ".jpg", ".jpeg", ".gif")):
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
+