ashishkblink commited on
Commit
9bff3fa
·
verified ·
1 Parent(s): 79153eb

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +59 -24
app.py CHANGED
@@ -14,31 +14,66 @@ from huggingface_hub import hf_hub_download, snapshot_download
14
  from pathlib import Path
15
 
16
  # Try to import f5_tts - handle different possible locations
17
- try:
18
- from f5_tts.api import F5TTS
19
- from f5_tts.infer.utils_infer import preprocess_ref_audio_text
20
- except ImportError:
21
- # Try adding local paths
22
- current_dir = os.path.dirname(__file__)
23
- possible_paths = [
24
- os.path.join(current_dir, "vakya_model"),
25
- os.path.join(current_dir, "f5_tts"),
26
- os.path.join(current_dir, "..", "vakya_model"),
27
- ]
28
- for path in possible_paths:
29
- if os.path.exists(path):
30
- sys.path.insert(0, path)
31
- try:
32
- from f5_tts.api import F5TTS
33
- from f5_tts.infer.utils_infer import preprocess_ref_audio_text
34
- break
35
- except ImportError:
36
- continue
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  else:
38
- raise ImportError(
39
- "Could not import f5_tts. Please ensure the model code is available. "
40
- "You may need to include the f5_tts directory in your Space or install it as a package."
41
- )
 
 
 
 
42
 
43
  # Model configuration
44
  MODEL_REPO_ID = "ashishkblink/vakya2.0"
 
14
  from pathlib import Path
15
 
16
  # Try to import f5_tts - handle different possible locations
17
+ # The f5_tts directory should be in the same directory as app.py
18
+ current_dir = os.path.dirname(os.path.abspath(__file__))
19
+
20
+ # Add current directory to path (so we can import f5_tts if it's in the same dir)
21
+ if current_dir not in sys.path:
22
+ sys.path.insert(0, current_dir)
23
+
24
+ # Also check for f5_tts in common locations
25
+ possible_parent_paths = [
26
+ current_dir, # Same directory as app.py
27
+ os.path.join(current_dir, ".."), # Parent directory
28
+ "/app", # Common HF Spaces location
29
+ ]
30
+
31
+ f5_tts_imported = False
32
+ for parent_path in possible_parent_paths:
33
+ parent_path = os.path.abspath(parent_path)
34
+ f5_tts_path = os.path.join(parent_path, "f5_tts")
35
+
36
+ if os.path.exists(f5_tts_path) and os.path.isdir(f5_tts_path):
37
+ # Add parent directory to path (not f5_tts itself)
38
+ if parent_path not in sys.path:
39
+ sys.path.insert(0, parent_path)
40
+ try:
41
+ from f5_tts.api import F5TTS
42
+ from f5_tts.infer.utils_infer import preprocess_ref_audio_text
43
+ f5_tts_imported = True
44
+ print(f"✅ Successfully imported f5_tts from {parent_path}")
45
+ break
46
+ except ImportError as e:
47
+ print(f"⚠️ Tried {parent_path}, but import failed: {e}")
48
+ continue
49
+
50
+ if not f5_tts_imported:
51
+ # Try direct import (in case it's installed as a package)
52
+ try:
53
+ from f5_tts.api import F5TTS
54
+ from f5_tts.infer.utils_infer import preprocess_ref_audio_text
55
+ f5_tts_imported = True
56
+ print("✅ Successfully imported f5_tts (installed package)")
57
+ except ImportError:
58
+ pass
59
+
60
+ if not f5_tts_imported:
61
+ # Print debug information
62
+ print(f"❌ Current directory: {current_dir}")
63
+ print(f"❌ Python path: {sys.path[:5]}")
64
+ print(f"❌ Checking for f5_tts in: {current_dir}")
65
+ if os.path.exists(os.path.join(current_dir, "f5_tts")):
66
+ print(f" ✅ f5_tts directory exists at: {os.path.join(current_dir, 'f5_tts')}")
67
+ print(f" 📁 Contents: {os.listdir(os.path.join(current_dir, 'f5_tts'))[:10]}")
68
  else:
69
+ print(f" ❌ f5_tts directory NOT found")
70
+
71
+ raise ImportError(
72
+ f"Could not import f5_tts. Please ensure the model code is available.\n"
73
+ f"Current directory: {current_dir}\n"
74
+ f"Looking for f5_tts in: {current_dir}\n"
75
+ f"Python path: {sys.path[:3]}"
76
+ )
77
 
78
  # Model configuration
79
  MODEL_REPO_ID = "ashishkblink/vakya2.0"