yukee1992 commited on
Commit
3f92fa0
Β·
verified Β·
1 Parent(s): 988b63b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -19
app.py CHANGED
@@ -42,39 +42,62 @@ api = HfApi(token=HF_TOKEN)
42
  # DOWNLOAD FONTS FROM DATASET
43
  # =============================================
44
  def download_all_fonts():
45
- """Download all fonts from HF Dataset to local directory"""
46
  try:
47
  files = api.list_repo_files(repo_id=FONTS_DATASET, repo_type="dataset")
48
  fonts = {}
49
 
 
 
 
 
50
  for file in files:
51
  if file.endswith(('.ttf', '.otf', '.ttc')):
52
  font_name = os.path.basename(file)
53
  local_path = os.path.join(FONTS_DIR, font_name)
54
 
55
- if not os.path.exists(local_path):
56
- print(f"⬇️ Downloading font: {font_name}")
57
- hf_hub_download(
58
- repo_id=FONTS_DATASET,
59
- filename=file,
60
- local_dir=FONTS_DIR,
61
- local_dir_use_symlinks=False,
62
- repo_type="dataset",
63
- token=HF_TOKEN
64
- )
 
65
 
66
- # Store font info
67
- font_key = font_name.split('.')[0].lower().replace('-', '_')
68
- fonts[font_key] = {
69
- "path": local_path,
70
- "name": font_name,
71
- "display_name": font_name.replace('.ttf', '').replace('.otf', '').replace('.ttc', '').replace('-', ' ')
72
- }
 
 
 
 
 
 
 
 
 
73
 
74
  print(f"βœ… Loaded {len(fonts)} fonts")
 
 
 
 
 
 
 
75
  return fonts
76
  except Exception as e:
77
  print(f"❌ Failed to download fonts: {e}")
 
 
78
  return {}
79
 
80
  # Download fonts at startup
@@ -166,10 +189,25 @@ def upload_to_dataset(file_path, project_id, filename, subfolder="videos"):
166
  return None
167
 
168
  def get_font_path(font_family):
 
169
  font_family_lower = font_family.lower().replace(' ', '_')
 
 
 
 
 
 
 
 
 
 
170
  for key, font_info in FONTS.items():
171
  if font_family_lower in key or key in font_family_lower:
172
- return font_info["path"]
 
 
 
 
173
  return None
174
 
175
  # =============================================
 
42
  # DOWNLOAD FONTS FROM DATASET
43
  # =============================================
44
  def download_all_fonts():
45
+ """Download all fonts from HF Dataset to local directory - FIXED PATH"""
46
  try:
47
  files = api.list_repo_files(repo_id=FONTS_DATASET, repo_type="dataset")
48
  fonts = {}
49
 
50
+ # Ensure directory exists
51
+ os.makedirs(FONTS_DIR, exist_ok=True)
52
+ print(f"πŸ“ Fonts directory: {FONTS_DIR}")
53
+
54
  for file in files:
55
  if file.endswith(('.ttf', '.otf', '.ttc')):
56
  font_name = os.path.basename(file)
57
  local_path = os.path.join(FONTS_DIR, font_name)
58
 
59
+ print(f"⬇️ Downloading font: {font_name} to {local_path}")
60
+
61
+ # Download the font
62
+ downloaded_path = hf_hub_download(
63
+ repo_id=FONTS_DATASET,
64
+ filename=file,
65
+ repo_type="dataset",
66
+ token=HF_TOKEN,
67
+ local_dir=FONTS_DIR,
68
+ local_dir_use_symlinks=False
69
+ )
70
 
71
+ print(f"βœ… Downloaded to: {downloaded_path}")
72
+
73
+ # Verify file exists
74
+ if os.path.exists(downloaded_path):
75
+ file_size = os.path.getsize(downloaded_path)
76
+ print(f"πŸ“Š File size: {file_size} bytes")
77
+
78
+ # Store font info with correct path
79
+ font_key = font_name.split('.')[0].lower().replace('-', '_')
80
+ fonts[font_key] = {
81
+ "path": downloaded_path,
82
+ "name": font_name,
83
+ "display_name": font_name.replace('.ttf', '').replace('.otf', '').replace('.ttc', '').replace('-', ' ')
84
+ }
85
+ else:
86
+ print(f"❌ File not found after download: {downloaded_path}")
87
 
88
  print(f"βœ… Loaded {len(fonts)} fonts")
89
+ print(f"πŸ“‹ Font keys: {list(fonts.keys())}")
90
+
91
+ # Debug: List all files in FONTS_DIR
92
+ print(f"πŸ“ Files in {FONTS_DIR}:")
93
+ for f in os.listdir(FONTS_DIR):
94
+ print(f" - {f}")
95
+
96
  return fonts
97
  except Exception as e:
98
  print(f"❌ Failed to download fonts: {e}")
99
+ import traceback
100
+ traceback.print_exc()
101
  return {}
102
 
103
  # Download fonts at startup
 
189
  return None
190
 
191
  def get_font_path(font_family):
192
+ """Get font path from font family name - with debugging"""
193
  font_family_lower = font_family.lower().replace(' ', '_')
194
+ print(f"πŸ” Looking for font: {font_family}")
195
+ print(f"πŸ“‹ Available fonts: {list(FONTS.keys())}")
196
+
197
+ # Try exact match
198
+ if font_family_lower in FONTS:
199
+ path = FONTS[font_family_lower]["path"]
200
+ print(f"βœ… Found exact match: {path}")
201
+ return path
202
+
203
+ # Try partial match
204
  for key, font_info in FONTS.items():
205
  if font_family_lower in key or key in font_family_lower:
206
+ path = font_info["path"]
207
+ print(f"βœ… Found partial match: {key} -> {path}")
208
+ return path
209
+
210
+ print(f"❌ Font not found: {font_family}")
211
  return None
212
 
213
  # =============================================