| |
| """ |
| Push fixes directly to Hugging Face using the Hub API for more reliable authentication |
| """ |
| import os |
| import sys |
| import tempfile |
| import shutil |
| from getpass import getpass |
| from huggingface_hub import HfApi, create_repo |
|
|
| def push_fixes(): |
| print("=" * 60) |
| print(" Push AI Response and File Upload Fixes to Hugging Face Space") |
| print("=" * 60) |
| |
| |
| username = input("Enter your Hugging Face username: ") |
| token = getpass("Enter your Hugging Face token: ") |
| space_name = input("Enter your Space name (just the name, not including your username): ") |
| |
| try: |
| |
| api = HfApi(token=token) |
| |
| |
| print("\nAuthenticating with Hugging Face...") |
| user_info = api.whoami() |
| print(f"Authenticated as: {user_info['name']} (@{user_info['fullname']})") |
| |
| |
| repo_id = f"{username}/{space_name}" |
| print(f"\nPreparing to update Space: {repo_id}") |
| print(f"Space URL: https://huggingface.co/spaces/{repo_id}") |
| |
| |
| files_to_upload = [ |
| "app/core/memory.py", |
| "app/core/ingestion.py", |
| "app/ui/streamlit_app.py" |
| ] |
| |
| |
| print("\nUploading files:") |
| for file_path in files_to_upload: |
| try: |
| print(f" - Uploading {file_path}...") |
| api.upload_file( |
| path_or_fileobj=file_path, |
| path_in_repo=file_path, |
| repo_id=repo_id, |
| repo_type="space", |
| commit_message=f"Fix: Improve {os.path.basename(file_path)} for better AI responses and file uploads" |
| ) |
| print(f" Success!") |
| except Exception as e: |
| print(f" Error uploading {file_path}: {str(e)}") |
| return False |
| |
| print("\n✅ All files uploaded successfully!") |
| print(f"View your Space at: https://huggingface.co/spaces/{username}/{space_name}") |
| print("Note: It may take a few minutes for your Space to rebuild with the new changes.") |
| return True |
| |
| except Exception as e: |
| print(f"\n❌ Error: {str(e)}") |
| return False |
|
|
| if __name__ == "__main__": |
| |
| try: |
| import huggingface_hub |
| except ImportError: |
| print("Error: huggingface_hub package is not installed.") |
| print("Installing huggingface_hub...") |
| import subprocess |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "huggingface_hub"]) |
| print("huggingface_hub installed. Please run the script again.") |
| sys.exit(1) |
| |
| |
| if push_fixes(): |
| print("\nPush completed successfully.") |
| else: |
| print("\nPush failed. Please check the error messages above.") |
| sys.exit(1) |