innoai commited on
Commit
706cef0
·
verified ·
1 Parent(s): 73a4bc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -2
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import os
2
  import subprocess
3
  import gradio as gr
 
4
 
5
  # 程序根目录
6
  BASE_DIR = os.path.dirname(__file__)
@@ -10,12 +11,31 @@ BINARY_PATH = os.path.join(BASE_DIR, "PptxToJpgZip")
10
  # 启动时确保二进制有执行权限(在 Hugging Face Spaces 里无法手动 chmod)
11
  try:
12
  os.chmod(BINARY_PATH, 0o755)
13
- # 针对整个运行目录
14
- subprocess.run(["fc-cache", "-f", "-v", os.getcwd()], check=True)
15
  except Exception as e:
16
  # 如果权限设置失败,也无需中断,只要后续能调用即可
17
  print(f"⚠️ 警告:设置执行权限失败:{e}")
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  def convert_pptx_to_zip(pptx_file):
20
  """
21
  调用外部 PptxToJpgZip,可执行文件将上传的 PPTX 转为 JPG 并打包 ZIP。
 
1
  import os
2
  import subprocess
3
  import gradio as gr
4
+ import shutil
5
 
6
  # 程序根目录
7
  BASE_DIR = os.path.dirname(__file__)
 
11
  # 启动时确保二进制有执行权限(在 Hugging Face Spaces 里无法手动 chmod)
12
  try:
13
  os.chmod(BINARY_PATH, 0o755)
 
 
14
  except Exception as e:
15
  # 如果权限设置失败,也无需中断,只要后续能调用即可
16
  print(f"⚠️ 警告:设置执行权限失败:{e}")
17
 
18
+ # 1. 定位源目录:仓库根目录(当前工作目录)
19
+ src_dir = os.getcwd()
20
+
21
+ # 2. 目标目录:用户字体目录(可写)
22
+ dst_dir = os.path.expanduser("~/.local/share/fonts")
23
+ os.makedirs(dst_dir, exist_ok=True)
24
+
25
+ # 3. 复制根目录下的所有 .ttf 和 .otf 文件
26
+ for fname in os.listdir(src_dir):
27
+ if fname.lower().endswith((".ttf", ".otf")):
28
+ shutil.copy(
29
+ os.path.join(src_dir, fname),
30
+ os.path.join(dst_dir, fname)
31
+ )
32
+
33
+ # 4. 刷新指定目录的字体缓存,确保新字体可用
34
+ subprocess.run(
35
+ ["fc-cache", "-f", "-v", dst_dir],
36
+ check=True
37
+ )
38
+
39
  def convert_pptx_to_zip(pptx_file):
40
  """
41
  调用外部 PptxToJpgZip,可执行文件将上传的 PPTX 转为 JPG 并打包 ZIP。