pycuts


Namepycuts JSON
Version 2.0.1 PyPI version JSON
download
home_pageNone
SummaryA collection of shortcut functions for common operations across various libraries.
upload_time2024-12-16 05:20:55
maintainerNone
docs_urlNone
authorDaniel Ialcin Misser Westergaard
requires_python>=3.7
licenseMIT License
keywords huggingface torch gradio utilities shortcuts
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pycuts

**pycuts** is a small Python library that provides a collection of shortcut functions for common operations across various libraries like Hugging Face, PyTorch, and Gradio.

## Features

- **HuggingFaceUtils**: Detect if you're running inside a Hugging Face Space, and if ZeroGPU hardware is being used.
- **TorchUtils**: Quickly check if a GPU-like accelerator (CUDA or MPS) is available, free GPU memory, or set random seeds for reproducibility.
- **GradioUtils**: Easily toggle between dark, light, or system appearance modes for Gradio interfaces.

## Installation

```bash
pip install pycuts
```

Optionally, install with extra dependencies:

```bash
# With PyTorch
pip install "pycuts[torch]"

# With Gradio
pip install "pycuts[gradio]"
```

## Quick Start

```python
import pycuts

# Check Hugging Face Space availability
if pycuts.is_spaces_available:
    print("Running inside a Hugging Face Space!")

# Check if GPU is available
if pycuts.is_gpu_available:
    print(f"GPU available, using device: {pycuts.get_device}")
else:
    print("No GPU, using CPU")

# Change Gradio Blocks appearance mode (requires Gradio installed)
# e.g. pycuts.gradio_utils.appearance("dark")
```

## Function Descriptions

### HuggingFaceUtils

| Function            | Description                                                                 |
|---------------------|-----------------------------------------------------------------------------|
| `spaces.is_available()` | Checks if the current script is running on a Hugging Face Space.            |
| `spaces.is_zero_gpu()`   | Checks if the Hugging Face Space is using ZeroGPU hardware.                |

### TorchUtils

| Function            | Description                                                                 |
|---------------------|-----------------------------------------------------------------------------|
| `is_gpu_available()` | Checks if any GPU-like accelerator (CUDA or MPS) is available.             |
| `empty_cache()`      | Frees up unused GPU memory by clearing the cache on CUDA devices.           |
| `get_device()`       | Determines which GPU-like accelerator is being used (CUDA, MPS, or CPU).   |
| `device_count()`     | Returns the number of available GPU-like devices.                          |
| `manual_seed(seed)`  | Sets the random seed for CPU and GPU contexts for reproducibility.          |

### GradioUtils

| Function            | Description                                                                 |
|---------------------|-----------------------------------------------------------------------------|
| `dark_mode()`        | Applies dark mode to a Gradio Blocks instance on load.                     |
| `light_mode()`       | Applies light mode to a Gradio Blocks instance on load.                    |
| `system_mode()`      | Applies the system's preferred color scheme (light or dark) to Gradio Blocks. |
| `appearance(mode)`   | Changes the appearance mode of a Gradio Blocks instance (dark, light, system). |

## Project Structure

- `pycuts/__init__.py` - Makes the main utilities easily accessible.
- `pycuts/pycuts.py` - Contains the implementations of the utility classes and functions.

## License

This project is licensed under the [MIT License](LICENSE).


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pycuts",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "huggingface, torch, gradio, utilities, shortcuts",
    "author": "Daniel Ialcin Misser Westergaard",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/42/2c/d7a41c0c60e8b932f4c3160bbfcd458d0cbdd35cf2e9fe53c67a2d42501d/pycuts-2.0.1.tar.gz",
    "platform": null,
    "description": "# pycuts\n\n**pycuts** is a small Python library that provides a collection of shortcut functions for common operations across various libraries like Hugging Face, PyTorch, and Gradio.\n\n## Features\n\n- **HuggingFaceUtils**: Detect if you're running inside a Hugging Face Space, and if ZeroGPU hardware is being used.\n- **TorchUtils**: Quickly check if a GPU-like accelerator (CUDA or MPS) is available, free GPU memory, or set random seeds for reproducibility.\n- **GradioUtils**: Easily toggle between dark, light, or system appearance modes for Gradio interfaces.\n\n## Installation\n\n```bash\npip install pycuts\n```\n\nOptionally, install with extra dependencies:\n\n```bash\n# With PyTorch\npip install \"pycuts[torch]\"\n\n# With Gradio\npip install \"pycuts[gradio]\"\n```\n\n## Quick Start\n\n```python\nimport pycuts\n\n# Check Hugging Face Space availability\nif pycuts.is_spaces_available:\n    print(\"Running inside a Hugging Face Space!\")\n\n# Check if GPU is available\nif pycuts.is_gpu_available:\n    print(f\"GPU available, using device: {pycuts.get_device}\")\nelse:\n    print(\"No GPU, using CPU\")\n\n# Change Gradio Blocks appearance mode (requires Gradio installed)\n# e.g. pycuts.gradio_utils.appearance(\"dark\")\n```\n\n## Function Descriptions\n\n### HuggingFaceUtils\n\n| Function            | Description                                                                 |\n|---------------------|-----------------------------------------------------------------------------|\n| `spaces.is_available()` | Checks if the current script is running on a Hugging Face Space.            |\n| `spaces.is_zero_gpu()`   | Checks if the Hugging Face Space is using ZeroGPU hardware.                |\n\n### TorchUtils\n\n| Function            | Description                                                                 |\n|---------------------|-----------------------------------------------------------------------------|\n| `is_gpu_available()` | Checks if any GPU-like accelerator (CUDA or MPS) is available.             |\n| `empty_cache()`      | Frees up unused GPU memory by clearing the cache on CUDA devices.           |\n| `get_device()`       | Determines which GPU-like accelerator is being used (CUDA, MPS, or CPU).   |\n| `device_count()`     | Returns the number of available GPU-like devices.                          |\n| `manual_seed(seed)`  | Sets the random seed for CPU and GPU contexts for reproducibility.          |\n\n### GradioUtils\n\n| Function            | Description                                                                 |\n|---------------------|-----------------------------------------------------------------------------|\n| `dark_mode()`        | Applies dark mode to a Gradio Blocks instance on load.                     |\n| `light_mode()`       | Applies light mode to a Gradio Blocks instance on load.                    |\n| `system_mode()`      | Applies the system's preferred color scheme (light or dark) to Gradio Blocks. |\n| `appearance(mode)`   | Changes the appearance mode of a Gradio Blocks instance (dark, light, system). |\n\n## Project Structure\n\n- `pycuts/__init__.py` - Makes the main utilities easily accessible.\n- `pycuts/pycuts.py` - Contains the implementations of the utility classes and functions.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A collection of shortcut functions for common operations across various libraries.",
    "version": "2.0.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/dwancin/pycuts/issues",
        "Documentation": "https://github.com/dwancin/pycuts#readme",
        "Homepage": "https://github.com/dwancin/pycuts",
        "Hugging Face": "https://huggingface.co/dwancin",
        "PyPI": "https://pypi.org/user/dwancin"
    },
    "split_keywords": [
        "huggingface",
        " torch",
        " gradio",
        " utilities",
        " shortcuts"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e740cf7635dc4b2d11f6af6d380c4590d1a56f700df085077b25aa37cbcc9b26",
                "md5": "701df37018b205ec6548ab6b5669c0a2",
                "sha256": "7f2ca5ac116ef846d4ffd93615a5149a9c1e647ef002d237543e707e2675c8dd"
            },
            "downloads": -1,
            "filename": "pycuts-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "701df37018b205ec6548ab6b5669c0a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4993,
            "upload_time": "2024-12-16T05:20:52",
            "upload_time_iso_8601": "2024-12-16T05:20:52.502044Z",
            "url": "https://files.pythonhosted.org/packages/e7/40/cf7635dc4b2d11f6af6d380c4590d1a56f700df085077b25aa37cbcc9b26/pycuts-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "422cd7a41c0c60e8b932f4c3160bbfcd458d0cbdd35cf2e9fe53c67a2d42501d",
                "md5": "7052ae51763da80c4cd2ae588e30dd80",
                "sha256": "d889f16977e74f0c0a0f8a9eb07223910fbefeee6d05b69e6f486e009f1e6e5f"
            },
            "downloads": -1,
            "filename": "pycuts-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "7052ae51763da80c4cd2ae588e30dd80",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 5035,
            "upload_time": "2024-12-16T05:20:55",
            "upload_time_iso_8601": "2024-12-16T05:20:55.163600Z",
            "url": "https://files.pythonhosted.org/packages/42/2c/d7a41c0c60e8b932f4c3160bbfcd458d0cbdd35cf2e9fe53c67a2d42501d/pycuts-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-16 05:20:55",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dwancin",
    "github_project": "pycuts",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pycuts"
}
        
Elapsed time: 0.50955s