factorstudios commited on
Commit
3e4e2e0
Β·
verified Β·
1 Parent(s): 16bb6c6

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +41 -17
server.py CHANGED
@@ -172,6 +172,7 @@ def compress_video(input_path: str, output_path: str) -> Dict:
172
  async def load_progress_file() -> Dict:
173
  """Load compression progress from JSON file in HF dataset."""
174
  try:
 
175
  # Try to download existing progress file
176
  progress_path = hf_hub_download(
177
  repo_id=HF_DATASET_REPO,
@@ -186,10 +187,12 @@ async def load_progress_file() -> Dict:
186
 
187
  with open(progress_path, 'r') as f:
188
  progress = json.load(f)
189
- print(f"βœ“ Loaded progress file: {len(progress.get('compressed', []))} files already processed")
 
 
190
  return progress
191
  except Exception as e:
192
- print(f"No existing progress file found, starting fresh: {e}")
193
  return {"compressed": [], "failed": [], "last_updated": datetime.now().isoformat()}
194
 
195
 
@@ -233,16 +236,26 @@ async def scan_and_compress_videos():
233
  compressed_files = {item["path"] for item in progress.get("compressed", [])}
234
  failed_files = {item["path"] for item in progress.get("failed", [])}
235
 
 
 
236
  print("\n" + "="*80)
237
  print("SCANNING FOR LARGE VIDEOS")
238
  print("="*80)
239
 
240
- # List all files in ready_videos
241
- files = list_repo_files(
242
- repo_id=HF_DATASET_REPO,
243
- repo_type="dataset",
244
- token=HF_TOKEN
245
- )
 
 
 
 
 
 
 
 
246
 
247
  # Find unprocessed video files
248
  video_files = []
@@ -272,7 +285,7 @@ async def scan_and_compress_videos():
272
  continue
273
 
274
  compression_state["total_found"] = len(video_files)
275
- print(f"Found {len(video_files)} unprocessed video files")
276
 
277
  if not video_files:
278
  print("βœ“ All videos already processed!")
@@ -389,15 +402,26 @@ async def scan_and_compress_videos():
389
 
390
  @app.on_event("startup")
391
  async def startup_event():
392
- """Start initial compression scan after 15 seconds."""
393
- async def delayed_scan():
394
- await asyncio.sleep(15)
395
- print("\n" + "="*80)
396
- print("STARTING COMPRESSION SCAN (15 seconds after startup)")
397
- print("="*80)
398
- await scan_and_compress_videos()
 
 
 
 
 
 
 
 
 
399
 
400
- asyncio.create_task(delayed_scan())
 
 
401
 
402
 
403
  @app.get("/")
 
172
  async def load_progress_file() -> Dict:
173
  """Load compression progress from JSON file in HF dataset."""
174
  try:
175
+ print("Attempting to load progress file from dataset...")
176
  # Try to download existing progress file
177
  progress_path = hf_hub_download(
178
  repo_id=HF_DATASET_REPO,
 
187
 
188
  with open(progress_path, 'r') as f:
189
  progress = json.load(f)
190
+ compressed_count = len(progress.get('compressed', []))
191
+ failed_count = len(progress.get('failed', []))
192
+ print(f"βœ“ Loaded progress: {compressed_count} compressed, {failed_count} failed")
193
  return progress
194
  except Exception as e:
195
+ print(f"⊘ No existing progress file or load failed: {str(e)[:100]}")
196
  return {"compressed": [], "failed": [], "last_updated": datetime.now().isoformat()}
197
 
198
 
 
236
  compressed_files = {item["path"] for item in progress.get("compressed", [])}
237
  failed_files = {item["path"] for item in progress.get("failed", [])}
238
 
239
+ print(f"Current state: {len(compressed_files)} compressed, {len(failed_files)} failed")
240
+
241
  print("\n" + "="*80)
242
  print("SCANNING FOR LARGE VIDEOS")
243
  print("="*80)
244
 
245
+ try:
246
+ # List all files in ready_videos
247
+ print("Connecting to Hugging Face dataset...")
248
+ files = list_repo_files(
249
+ repo_id=HF_DATASET_REPO,
250
+ repo_type="dataset",
251
+ token=HF_TOKEN
252
+ )
253
+ print(f"βœ“ Found {len(files)} total files in dataset")
254
+ except Exception as e:
255
+ print(f"βœ— Error listing files: {e}")
256
+ compression_state["last_error"] = str(e)
257
+ compression_state["is_polling"] = False
258
+ return
259
 
260
  # Find unprocessed video files
261
  video_files = []
 
285
  continue
286
 
287
  compression_state["total_found"] = len(video_files)
288
+ print(f"\nβœ“ Found {len(video_files)} unprocessed video files")
289
 
290
  if not video_files:
291
  print("βœ“ All videos already processed!")
 
402
 
403
  @app.on_event("startup")
404
  async def startup_event():
405
+ """Start compression scan on server startup."""
406
+ print("\n" + "="*80)
407
+ print("STARTUP EVENT TRIGGERED")
408
+ print("="*80)
409
+
410
+ # Check if ffmpeg/ffprobe are available
411
+ try:
412
+ result = subprocess.run(["ffmpeg", "-version"], capture_output=True, timeout=5)
413
+ if result.returncode == 0:
414
+ print("βœ“ ffmpeg is available")
415
+ else:
416
+ print("βœ— ffmpeg check failed")
417
+ except FileNotFoundError:
418
+ print("βœ— WARNING: ffmpeg not found in PATH - compression will fail")
419
+ except Exception as e:
420
+ print(f"βœ— Error checking ffmpeg: {e}")
421
 
422
+ # Schedule scan immediately instead of with delay
423
+ print("Starting compression scan immediately...")
424
+ await scan_and_compress_videos()
425
 
426
 
427
  @app.get("/")