jmanhype commited on
Commit
43e677e
·
1 Parent(s): d6ae642

Fix module imports and directory handling

Browse files
Files changed (2) hide show
  1. Dockerfile +10 -6
  2. app.py +32 -46
Dockerfile CHANGED
@@ -43,17 +43,18 @@ RUN pip install --no-cache-dir openmim && \
43
  mim install "mmdet>=3.1.0" && \
44
  mim install "mmpose>=1.1.0"
45
 
46
- # Clone and set up MuseV with exact case
47
- RUN git clone https://github.com/TMElyralab/MuseV.git && \
48
- mv MuseV musev_temp && \
49
- mv musev_temp MuseV && \
50
  cd MuseV && \
51
  git clone https://github.com/huggingface/diffusers.git && \
52
  git clone https://github.com/patrickvonplaten/controlnet_aux.git && \
53
  cd diffusers && pip install -e . && \
54
  cd ../controlnet_aux && pip install -e . && \
55
  cd .. && \
56
- cp -r scripts/gradio/* ../ && \
 
57
  chmod +x ../gradio_*.py
58
 
59
  # Set up Python path
@@ -68,7 +69,10 @@ RUN echo "Current directory:" && pwd && \
68
  echo "MuseV directory contents:" && ls -la MuseV && \
69
  echo "Gradio scripts directory contents:" && ls -la MuseV/scripts/gradio && \
70
  echo "Python path:" && echo $PYTHONPATH && \
71
- echo "Checking gradio scripts:" && ls -la gradio_*.py
 
 
 
72
 
73
  EXPOSE 7860
74
 
 
43
  mim install "mmdet>=3.1.0" && \
44
  mim install "mmpose>=1.1.0"
45
 
46
+ # Clone and set up MuseV
47
+ RUN git clone https://github.com/TMElyralab/MuseV.git /tmp/MuseV && \
48
+ mkdir -p MuseV && \
49
+ cp -r /tmp/MuseV/* MuseV/ && \
50
  cd MuseV && \
51
  git clone https://github.com/huggingface/diffusers.git && \
52
  git clone https://github.com/patrickvonplaten/controlnet_aux.git && \
53
  cd diffusers && pip install -e . && \
54
  cd ../controlnet_aux && pip install -e . && \
55
  cd .. && \
56
+ cp -r scripts/gradio/gradio_video2video.py ../gradio_video2video.py && \
57
+ cp -r scripts/gradio/gradio_text2video.py ../gradio_text2video.py && \
58
  chmod +x ../gradio_*.py
59
 
60
  # Set up Python path
 
69
  echo "MuseV directory contents:" && ls -la MuseV && \
70
  echo "Gradio scripts directory contents:" && ls -la MuseV/scripts/gradio && \
71
  echo "Python path:" && echo $PYTHONPATH && \
72
+ echo "Checking gradio scripts:" && ls -la gradio_*.py && \
73
+ echo "Verifying file contents:" && \
74
+ head -n 1 gradio_video2video.py && \
75
+ head -n 1 gradio_text2video.py
76
 
77
  EXPOSE 7860
78
 
app.py CHANGED
@@ -8,24 +8,27 @@ import numpy as np
8
  import gradio as gr
9
  import spaces
10
  import cuid
 
11
 
12
  from huggingface_hub import snapshot_download
13
 
14
  print("Starting application...")
15
 
 
 
 
 
 
 
 
 
 
 
 
16
  # Set up paths
17
  ProjectDir = os.path.dirname(os.path.abspath(__file__))
18
  CheckpointsDir = os.path.join(ProjectDir, "checkpoints")
19
-
20
- # Look for MuseV directory with either case
21
- if os.path.exists(os.path.join(ProjectDir, "MuseV")):
22
- MuseVDir = os.path.join(ProjectDir, "MuseV")
23
- elif os.path.exists(os.path.join(ProjectDir, "musev")):
24
- MuseVDir = os.path.join(ProjectDir, "musev")
25
- else:
26
- print("Error: Could not find MuseV directory")
27
- sys.exit(1)
28
-
29
  GradioScriptsDir = os.path.join(MuseVDir, "scripts", "gradio")
30
 
31
  print(f"Project directory: {ProjectDir}")
@@ -35,11 +38,11 @@ print(f"Gradio scripts directory: {GradioScriptsDir}")
35
  # Add the MuseV paths to sys.path
36
  paths_to_add = [
37
  ProjectDir, # Add current directory first
38
- GradioScriptsDir,
39
  MuseVDir,
40
  os.path.join(MuseVDir, "MMCM"),
41
  os.path.join(MuseVDir, "diffusers", "src"),
42
- os.path.join(MuseVDir, "controlnet_aux", "src")
 
43
  ]
44
 
45
  for path in paths_to_add:
@@ -74,46 +77,29 @@ for path in sys.path:
74
 
75
  print("Attempting to import gradio modules...")
76
 
77
- # First check if the files exist in the current directory
78
- print("Checking for gradio module files...")
79
  video2video_path = os.path.join(ProjectDir, "gradio_video2video.py")
80
  text2video_path = os.path.join(ProjectDir, "gradio_text2video.py")
81
- print(f"Looking for video2video at: {video2video_path}")
82
- print(f"Looking for text2video at: {text2video_path}")
83
-
84
- if os.path.exists(video2video_path):
85
- print(f"Found video2video at {video2video_path}")
86
- else:
87
- print(f"Warning: video2video not found at {video2video_path}")
88
 
89
- if os.path.exists(text2video_path):
90
- print(f"Found text2video at {text2video_path}")
91
- else:
92
- print(f"Warning: text2video not found at {text2video_path}")
93
 
94
- # Try importing from current directory first
95
  try:
96
- import gradio_video2video
97
- import gradio_text2video
98
- online_v2v_inference = gradio_video2video.online_v2v_inference
99
- online_t2v_inference = gradio_text2video.online_t2v_inference
100
- print("Successfully imported gradio modules from current directory")
 
101
  except Exception as e:
102
- print(f"Error importing from current directory: {str(e)}")
103
- print("Attempting to import from MuseV directory...")
104
- try:
105
- sys.path.insert(0, os.path.join(MuseVDir, "scripts", "gradio"))
106
- from gradio_video2video import online_v2v_inference
107
- from gradio_text2video import online_t2v_inference
108
- print("Successfully imported from MuseV directory")
109
- except Exception as e2:
110
- print(f"Error importing from MuseV directory: {str(e2)}")
111
- print("Current directory contents:")
112
- print(os.listdir('.'))
113
- if os.path.exists(GradioScriptsDir):
114
- print("Gradio scripts directory contents:")
115
- print(os.listdir(GradioScriptsDir))
116
- sys.exit(1)
117
 
118
  ignore_video2video = False
119
  max_image_edge = 1280
 
8
  import gradio as gr
9
  import spaces
10
  import cuid
11
+ import importlib.util
12
 
13
  from huggingface_hub import snapshot_download
14
 
15
  print("Starting application...")
16
 
17
+ def import_from_path(module_name, file_path):
18
+ """Import a module from a file path."""
19
+ if not os.path.exists(file_path):
20
+ raise ImportError(f"File not found: {file_path}")
21
+
22
+ print(f"Importing {module_name} from {file_path}")
23
+ spec = importlib.util.spec_from_file_location(module_name, file_path)
24
+ module = importlib.util.module_from_spec(spec)
25
+ spec.loader.exec_module(module)
26
+ return module
27
+
28
  # Set up paths
29
  ProjectDir = os.path.dirname(os.path.abspath(__file__))
30
  CheckpointsDir = os.path.join(ProjectDir, "checkpoints")
31
+ MuseVDir = os.path.join(ProjectDir, "MuseV") # We ensure this is capitalized in Dockerfile
 
 
 
 
 
 
 
 
 
32
  GradioScriptsDir = os.path.join(MuseVDir, "scripts", "gradio")
33
 
34
  print(f"Project directory: {ProjectDir}")
 
38
  # Add the MuseV paths to sys.path
39
  paths_to_add = [
40
  ProjectDir, # Add current directory first
 
41
  MuseVDir,
42
  os.path.join(MuseVDir, "MMCM"),
43
  os.path.join(MuseVDir, "diffusers", "src"),
44
+ os.path.join(MuseVDir, "controlnet_aux", "src"),
45
+ GradioScriptsDir
46
  ]
47
 
48
  for path in paths_to_add:
 
77
 
78
  print("Attempting to import gradio modules...")
79
 
80
+ # Try importing from current directory first
 
81
  video2video_path = os.path.join(ProjectDir, "gradio_video2video.py")
82
  text2video_path = os.path.join(ProjectDir, "gradio_text2video.py")
 
 
 
 
 
 
 
83
 
84
+ print(f"Looking for modules at:")
85
+ print(f"video2video: {video2video_path}")
86
+ print(f"text2video: {text2video_path}")
 
87
 
 
88
  try:
89
+ print("Attempting to import from current directory...")
90
+ video2video = import_from_path("gradio_video2video", video2video_path)
91
+ text2video = import_from_path("gradio_text2video", text2video_path)
92
+ online_v2v_inference = video2video.online_v2v_inference
93
+ online_t2v_inference = text2video.online_t2v_inference
94
+ print("Successfully imported modules")
95
  except Exception as e:
96
+ print(f"Error importing modules: {str(e)}")
97
+ print("\nDirectory contents:")
98
+ print(os.listdir(ProjectDir))
99
+ if os.path.exists(GradioScriptsDir):
100
+ print("\nGradio scripts directory contents:")
101
+ print(os.listdir(GradioScriptsDir))
102
+ sys.exit(1)
 
 
 
 
 
 
 
 
103
 
104
  ignore_video2video = False
105
  max_image_edge = 1280