LYL1015 commited on
Commit
afec329
·
verified ·
1 Parent(s): 9d03193

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -1,4 +1,36 @@
1
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import subprocess
3
  import os
4
  from pathlib import Path
 
1
  import os
2
+ import subprocess
3
+ import os
4
+ from pathlib import Path
5
+ BASE_DIR = Path("/home/user/app")
6
+ commands = [
7
+ ("python -V", BASE_DIR),
8
+ ("pip install gradio_image_annotation", BASE_DIR)
9
+ ]
10
+
11
+ def run_command(cmd, cwd=None):
12
+ try:
13
+ result = subprocess.run(
14
+ cmd, # 注意:这里不再使用 shlex.split()
15
+ cwd=str(cwd) if cwd else None,
16
+ shell=True, # 需要 shell=True 来支持 && 等操作符
17
+ check=True,
18
+ stdout=subprocess.PIPE,
19
+ stderr=subprocess.PIPE,
20
+ text=True
21
+ )
22
+ print(f"[SUCCESS] {cmd}")
23
+ if result.stdout: print(result.stdout)
24
+ return True
25
+ except subprocess.CalledProcessError as e:
26
+ print(f"[FAILED] {cmd}")
27
+ print(f"Error: {e.stderr}")
28
+ return False
29
+
30
+ for cmd, cwd in commands:
31
+ run_command(cmd, cwd)
32
+
33
+
34
  import subprocess
35
  import os
36
  from pathlib import Path