qihfang commited on
Commit
8c4a54c
·
1 Parent(s): f71f9e4

Add Code for ViTPose Installation

Browse files
Files changed (1) hide show
  1. app.py +52 -1
app.py CHANGED
@@ -1,3 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import numpy as np
3
  import cv2
@@ -554,4 +603,6 @@ def create_interface():
554
 
555
  if __name__ == "__main__":
556
  demo = create_interface()
557
- demo.launch(server_name="0.0.0.0", server_port=7860, share=True, show_error=True)
 
 
 
1
+ import importlib
2
+ import importlib.util
3
+ import subprocess
4
+ import sys
5
+ import os
6
+
7
+ def ensure_mmpose_installed(local_path='/data/WHAM/third-party/ViTPose'):
8
+ """
9
+ Check if 'mmpose' can be imported; if not, attempt to install it from local_path.
10
+ local_path should contain setup.py or pyproject.toml so that pip can install it.
11
+ """
12
+ package_name = 'mmpose'
13
+ # Try to find the spec for import
14
+ spec = importlib.util.find_spec(package_name)
15
+ if spec is not None:
16
+ try:
17
+ module = importlib.import_module(package_name)
18
+ print(f"'{package_name}' is already installed, version: {getattr(module, '__version__', 'unknown')}")
19
+ return True
20
+ except Exception as e:
21
+ print(f"Found '{package_name}', but import failed: {e}. Will attempt re-install.")
22
+ else:
23
+ print(f"'{package_name}' not found, attempting installation...")
24
+
25
+ # If we reach here, we need to install or reinstall
26
+ # Check that the directory exists
27
+ if not os.path.isdir(local_path):
28
+ raise FileNotFoundError(f"Specified install directory does not exist: {local_path}")
29
+
30
+ # Construct pip install command using the current Python executable
31
+ cmd = [sys.executable, "-m", "pip", "install", local_path]
32
+ print("Running command:", " ".join(cmd))
33
+ try:
34
+ subprocess.check_call(cmd)
35
+ except subprocess.CalledProcessError as e:
36
+ raise RuntimeError(f"Failed to install mmpose: {e}")
37
+
38
+ # After installation, try importing again
39
+ try:
40
+ module = importlib.import_module(package_name)
41
+ print(f"'{package_name}' installed and imported successfully, version: {getattr(module, '__version__', 'unknown')}")
42
+ return True
43
+ except Exception as e:
44
+ raise RuntimeError(f"Installed but still cannot import '{package_name}': {e}")
45
+
46
+ ensure_mmpose_installed('/data/WHAM/third-party/ViTPose')
47
+
48
+
49
+
50
  import gradio as gr
51
  import numpy as np
52
  import cv2
 
603
 
604
  if __name__ == "__main__":
605
  demo = create_interface()
606
+ port = int(os.environ.get("GRADIO_SERVER_PORT", os.environ.get("PORT", 7860)))
607
+ server_name = str(os.environ.get("GRADIO_SERVER_NAME", "0.0.0.0"))
608
+ demo.launch(server_name=server_name, server_port=port, share=True, show_error=True)