from roboflow import Roboflow
import os

print("Authenticating with Roboflow...")
rf = Roboflow(api_key="FAPGIPfHsatskiNQsHY2")

print("Fetching project...")
project = rf.workspace("cracked-steel").project("wall-crack-detection-vxhsb")

print("Downloading dataset...")
# Try version 1 or the latest available
try:
    dataset = project.version(1).download("yolov8")
    print(f"Dataset downloaded to: {dataset.location}")
except Exception as e:
    print(f"Error with version 1: {e}")
    # Fallback to getting all versions and picking the first
    versions = project.versions()
    if versions:
        dataset = versions[0].download("yolov8")
        print(f"Dataset downloaded to: {dataset.location}")
    else:
        print("No versions found!")
