Spaces:
Runtime error
Runtime error
Update app.py
Browse files14 unmodified lines1516171819202122232425112 unmodified lines1381391401411421431441451 unmodified line14714814915015115215315415529 unmodified lines185186187188189190191192193194195196197198199200201202203204205206207115 unmodified lines3233243253263273283291 unmodified line33133233333433533633733814 unmodified linesimport ioimport time# Set up a progress callback for huggingface_hubfrom huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError, HfHubHTTPErrorfrom huggingface_hub.utils._errors import LocalEntryNotFoundErrorfrom huggingface_hub.file_download import http_getfrom huggingface_hub import HfFileSystem# Configure Hugging Face cache and environmentos.environ["HF_HOME"] = os.path.join(os.getcwd(), ".cache/huggingface")112 unmodified lines# Pre-check model availabilitytry:from huggingface_hub import model_info# Try to get token firsttoken = get_hf_token()1 unmodified line# Check if the model is available in Hugging Facetry:model_status.info("Checking model access...")info = model_info("black-forest-labs/FLUX.1-Fill-dev", token=token)model_status.success(f"Model verified: {info.id}")model_status.info(f"Model tags: {', '.join(info.tags)}")except Exception as access_error:model_status.error(f"Model access check failed: {str(access_error)}")else:29 unmodified linesdownload_progress = st.empty()progress_callback = DownloadProgressCallback(download_progress)# Set up huggingface_hub to use our progress callbackfrom huggingface_hub import snapshot_download# Download snapshot first to ensure we have all files with progressprogress_placeholder.text("Starting model files download...")try:# Try to download the model snapshot firstsnapshot_download(repo_id="black-forest-labs/FLUX.1-Fill-dev",token=token,local_dir="model_cache",local_dir_use_symlinks=False,force_download=False,resume_download=True,max_workers=4,progressbar=True)download_progress.text("Download completed successfully!")except Exception as download_error:download_progress.text(f"Snapshot download error: {str(download_error)}")115 unmodified linesif token:# First log in explicitlycomp_progress.text("Logging in with token...")login(token)# Verify login worked and we have accesscomp_progress.text("Verifying model access...")1 unmodified linetry:# Check if we can access the modelwith timeout(30): # 30 seconds timeout for API checkmodel_info = api.model_info("black-forest-labs/FLUX.1-Fill-dev")comp_progress.text(f"Access verified to model: {model_info.id}")except Exception as access_error:st.error(f"Authentication succeeded but access verification failed: {str(access_error)}")if "401" in str(access_error) or "access" in str(access_error).lower():14 unmodified lines15161718192021222324252627282930112 unmodified lines1431441451461471481 unmodified line15015115215315415515615715815916016116216316416516616716816917017117229 unmodified lines202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235115 unmodified lines3513523533543553563573583593603611 unmodified line36336436536636736836937014 unmodified linesimport ioimport time# Set up imports for huggingface_hub# Import what we can, but handle potential import errorstry:from huggingface_hub import HfApi, HfFolder, Repository, create_repo, model_info, hf_hub_downloadfrom huggingface_hub import login as hf_loginexcept ImportError as e:st.error(f"Error importing from huggingface_hub: {e}")# Don't rely on specific internal modules that might change between versions# We'll handle errors more gracefully instead# Configure Hugging Face cache and environmentos.environ["HF_HOME"] = os.path.join(os.getcwd(), ".cache/huggingface")112 unmodified lines# Pre-check model availabilitytry:# Try to get token firsttoken = get_hf_token()1 unmodified line# Check if the model is available in Hugging Facetry:model_status.info("Checking model access...")# Use safer HfApi instead of direct model_info if possibleapi = HfApi()try:info = api.model_info("black-forest-labs/FLUX.1-Fill-dev")model_status.success(f"Model verified: {info.id}")if hasattr(info, 'tags'):model_status.info(f"Model tags: {', '.join(info.tags)}")except Exception as api_error:# Try fallback with model_infotry:info = model_info("black-forest-labs/FLUX.1-Fill-dev", token=token)model_status.success(f"Model verified: {info.id}")if hasattr(info, 'tags'):model_status.info(f"Model tags: {', '.join(info.tags)}")except Exception:raise api_errorexcept Exception as access_error:model_status.error(f"Model access check failed: {str(access_error)}")else:29 unmodified linesdownload_progress = st.empty()progress_callback = DownloadProgressCallback(download_progress)# Try pre-downloading files to ensure all components are availableprogress_placeholder.text("Starting model files download...")try:# Try to download individual files one by one instead of snapshot# This is more robust across different huggingface_hub versionsprogress_placeholder.text("Downloading model files using hf_hub_download...")# List of essential files to try downloadingessential_files = ["config.json","scheduler/scheduler_config.json","tokenizer/tokenizer_config.json"]# Try downloading files one by onefor file_path in essential_files:try:progress_placeholder.text(f"Downloading {file_path}...")hf_hub_download(repo_id="black-forest-labs/FLUX.1-Fill-dev",filename=file_path,token=token,local_dir="model_cache",resume_download=True)except Exception as file_error:progress_placeholder.text(f"Error downloading {file_path}: {str(file_error)}")# Continue with the next filedownload_progress.text("Download completed successfully!")except Exception as download_error:download_progress.text(f"Snapshot download error: {str(download_error)}")115 unmodified linesif token:# First log in explicitlycomp_progress.text("Logging in with token...")try:hf_login(token)except Exception as login_error:comp_progress.error(f"Login error (non-critical): {str(login_error)}")# Continue anyway as the token parameter will be used# Verify login worked and we have accesscomp_progress.text("Verifying model access...")1 unmodified linetry:# Check if we can access the modelwith timeout(30): # 30 seconds timeout for API checkmodel_info_obj = api.model_info("black-forest-labs/FLUX.1-Fill-dev")comp_progress.text(f"Access verified to model: {model_info_obj.id if hasattr(model_info_obj, 'id') else 'black-forest-labs/FLUX.1-Fill-dev'}")except Exception as access_error:st.error(f"Authentication succeeded but access verification failed: {str(access_error)}")if "401" in str(access_error) or "access" in str(access_error).lower():
app.py+60-28