oKen38461 commited on
Commit
f4998a2
·
1 Parent(s): 7d52a6e

ファイルタイプのインポートエラー処理を追加し、モデルの初期化時に遅延インポートを実装しました。また、`requirements.txt`で`filetype`のバージョンを指定しました。

Browse files
Files changed (3) hide show
  1. app.py +20 -2
  2. core/atomic_components/loader.py +25 -9
  3. requirements.txt +1 -1
app.py CHANGED
@@ -4,8 +4,19 @@ import tempfile
4
  import shutil
5
  from pathlib import Path
6
  from model_manager import ModelManager
7
- from stream_pipeline_offline import StreamSDK
8
- from inference import run, seed_everything
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  # モデルの初期化
11
  print("=== モデルの初期化開始 ===")
@@ -26,10 +37,17 @@ else:
26
  cfg_pkl = "./checkpoints/ditto_cfg/v0.4_hubert_cfg_trt.pkl"
27
 
28
  try:
 
 
 
 
 
29
  SDK = StreamSDK(cfg_pkl, data_root)
30
  print("✅ SDK初期化成功")
31
  except Exception as e:
32
  print(f"❌ SDK初期化エラー: {e}")
 
 
33
  raise
34
 
35
  def process_talking_head(audio_file, source_image):
 
4
  import shutil
5
  from pathlib import Path
6
  from model_manager import ModelManager
7
+
8
+ # インポートエラーのデバッグ情報を表示
9
+ try:
10
+ import filetype
11
+ print("✅ filetype module imported successfully")
12
+ except ImportError as e:
13
+ print(f"⚠️ filetype import failed: {e}")
14
+ print("Using fallback file type detection")
15
+
16
+ # 遅延インポート(モデルダウンロード後)
17
+ StreamSDK = None
18
+ run = None
19
+ seed_everything = None
20
 
21
  # モデルの初期化
22
  print("=== モデルの初期化開始 ===")
 
37
  cfg_pkl = "./checkpoints/ditto_cfg/v0.4_hubert_cfg_trt.pkl"
38
 
39
  try:
40
+ # モジュールをインポート
41
+ global StreamSDK, run, seed_everything
42
+ from stream_pipeline_offline import StreamSDK
43
+ from inference import run, seed_everything
44
+
45
  SDK = StreamSDK(cfg_pkl, data_root)
46
  print("✅ SDK初期化成功")
47
  except Exception as e:
48
  print(f"❌ SDK初期化エラー: {e}")
49
+ import traceback
50
+ traceback.print_exc()
51
  raise
52
 
53
  def process_talking_head(audio_file, source_image):
core/atomic_components/loader.py CHANGED
@@ -1,16 +1,32 @@
1
- import filetype
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import imageio
3
  import cv2
4
 
5
 
6
- def is_image(file_path):
7
- return filetype.is_image(file_path)
8
-
9
-
10
- def is_video(file_path):
11
- return filetype.is_video(file_path)
12
-
13
-
14
  def check_resize(h, w, max_dim=1920, division=2):
15
  rsz_flag = False
16
  # ajust the size of the image according to the maximum dimension
 
1
+ try:
2
+ import filetype
3
+ def is_image(file_path):
4
+ return filetype.is_image(file_path)
5
+
6
+ def is_video(file_path):
7
+ return filetype.is_video(file_path)
8
+ except ImportError:
9
+ # Fallback implementation if filetype is not available
10
+ import os
11
+
12
+ def is_image(file_path):
13
+ """Check if file is an image based on extension"""
14
+ if not os.path.exists(file_path):
15
+ return False
16
+ ext = os.path.splitext(file_path)[1].lower()
17
+ return ext in ['.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp']
18
+
19
+ def is_video(file_path):
20
+ """Check if file is a video based on extension"""
21
+ if not os.path.exists(file_path):
22
+ return False
23
+ ext = os.path.splitext(file_path)[1].lower()
24
+ return ext in ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv', '.webm', '.m4v']
25
+
26
  import imageio
27
  import cv2
28
 
29
 
 
 
 
 
 
 
 
 
30
  def check_resize(h, w, max_dim=1920, division=2):
31
  rsz_flag = False
32
  # ajust the size of the image according to the maximum dimension
requirements.txt CHANGED
@@ -45,7 +45,7 @@ cffi
45
  # Additional dependencies for compatibility
46
  packaging
47
  typing-extensions
48
- filetype
49
 
50
  # ONNX Runtime for model inference
51
  onnxruntime-gpu # GPU版のみで十分(CPU版も含まれる)
 
45
  # Additional dependencies for compatibility
46
  packaging
47
  typing-extensions
48
+ filetype==1.2.0
49
 
50
  # ONNX Runtime for model inference
51
  onnxruntime-gpu # GPU版のみで十分(CPU版も含まれる)