1inkusFace commited on
Commit
8f08323
Β·
verified Β·
1 Parent(s): cd23e50

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -17
app.py CHANGED
@@ -37,12 +37,10 @@ LOAD_DETOKENIZER = os.getenv("KIMI_LOAD_DETOKENIZER", "1") == "1"
37
  # Kimi-Audio install (once per Space container)
38
  # ---------------------------------------------------------------------------
39
 
40
-
41
  def _ensure_kimia_infer():
42
  """Clone Moonshot repo with submodules and install editable."""
43
  try:
44
  from kimia_infer.api.kimia import KimiAudio # type: ignore
45
-
46
  return KimiAudio
47
  except ImportError:
48
  pass
@@ -51,31 +49,49 @@ def _ensure_kimia_infer():
51
  print(f"πŸ“¦ Cloning Kimi-Audio β†’ {KIMI_AUDIO_DIR}")
52
  subprocess.run(
53
  [
54
- "git",
55
- "clone",
56
- "--recursive",
57
- "--depth",
58
- "1",
59
- KIMI_AUDIO_REPO,
60
- KIMI_AUDIO_DIR,
61
  ],
62
  check=True,
63
  )
64
 
 
 
 
 
 
65
  print("🎡 Installing kimia_infer (editable)...")
66
- subprocess.run(
 
 
67
  [
68
  sys.executable, "-m", "pip", "install", "-q",
69
  "-e", KIMI_AUDIO_DIR,
70
- "--no-build-isolation", # ← critical
 
71
  ],
72
- check=True,
 
73
  )
74
-
75
- from kimia_infer.api.kimia import KimiAudio # type: ignore
76
-
77
- return KimiAudio
78
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  def _apply_transformers_patches() -> None:
81
  """Bridge Kimi-Audio remote code with common HF Space transformers builds."""
 
37
  # Kimi-Audio install (once per Space container)
38
  # ---------------------------------------------------------------------------
39
 
 
40
  def _ensure_kimia_infer():
41
  """Clone Moonshot repo with submodules and install editable."""
42
  try:
43
  from kimia_infer.api.kimia import KimiAudio # type: ignore
 
44
  return KimiAudio
45
  except ImportError:
46
  pass
 
49
  print(f"πŸ“¦ Cloning Kimi-Audio β†’ {KIMI_AUDIO_DIR}")
50
  subprocess.run(
51
  [
52
+ "git", "clone", "--recursive", "--depth", "1",
53
+ KIMI_AUDIO_REPO, KIMI_AUDIO_DIR,
 
 
 
 
 
54
  ],
55
  check=True,
56
  )
57
 
58
+ # Safety net: make the source tree importable even if the editable
59
+ # install's .pth is not picked up by the current process.
60
+ if KIMI_AUDIO_DIR not in sys.path:
61
+ sys.path.insert(0, KIMI_AUDIO_DIR)
62
+
63
  print("🎡 Installing kimia_infer (editable)...")
64
+ # Use --no-deps so flash-attn does not try to rebuild.
65
+ # (We will handle flash-attn separately if needed.)
66
+ result = subprocess.run(
67
  [
68
  sys.executable, "-m", "pip", "install", "-q",
69
  "-e", KIMI_AUDIO_DIR,
70
+ "--no-deps",
71
+ "--no-build-isolation",
72
  ],
73
+ capture_output=True,
74
+ text=True,
75
  )
76
+ if result.returncode != 0:
77
+ print("pip install failed:")
78
+ print(result.stdout)
79
+ print(result.stderr)
80
+ # Still try the import via sys.path β€” often enough for kimia_infer
81
+ # because most of it is pure Python.
82
+
83
+ # Final import attempt
84
+ try:
85
+ from kimia_infer.api.kimia import KimiAudio # type: ignore
86
+ print("βœ… kimia_infer imported successfully")
87
+ return KimiAudio
88
+ except ImportError as e:
89
+ # Extra debug
90
+ print(f"❌ Still cannot import kimia_infer: {e}")
91
+ print(f"sys.path[0:5] = {sys.path[:5]}")
92
+ print(f"Contents of {KIMI_AUDIO_DIR}:")
93
+ subprocess.run(["ls", "-la", KIMI_AUDIO_DIR], check=False)
94
+ raise
95
 
96
  def _apply_transformers_patches() -> None:
97
  """Bridge Kimi-Audio remote code with common HF Space transformers builds."""