leptonai


Nameleptonai JSON
Version 0.22.8 PyPI version JSON
download
home_pageNone
SummaryLepton AI Platform
upload_time2025-02-13 01:31:59
maintainerNone
docs_urlNone
authorNone
requires_python<3.13,>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="https://raw.githubusercontent.com/leptonai/leptonai/main/assets/logo.svg" height=100>

# Lepton AI

**A Pythonic framework to simplify AI service building**

<a href="https://lepton.ai/">Homepage</a> •
<a href="https://dashboard.lepton.ai/playground">API Playground</a> •
<a href="https://github.com/leptonai/examples">Examples</a> •
<a href="https://lepton.ai/docs/">Documentation</a> •
<a href="https://lepton.ai/references">CLI References</a> •
<a href="https://twitter.com/leptonai">Twitter</a> •
<a href="https://leptonai.medium.com/">Blog</a>

The LeptonAI Python library allows you to build an AI service from Python code with ease. Key features include:

- A Pythonic abstraction `Photon`, allowing you to convert research and modeling code into a service with a few lines of code.
- Simple abstractions to launch models like those on [HuggingFace](https://huggingface.co) in few lines of code.
- Prebuilt examples for common models such as Llama, SDXL, Whisper, and others.
- AI tailored batteries included such as autobatching, background jobs, etc.
- A client to automatically call your service like native Python functions.
- Pythonic configuration specs to be readily shipped in a cloud environment.

## Getting started with one-liner
Install the library with:

```shell
pip install -U leptonai
```
This installs the `leptonai` Python library, as well as the commandline interface `lep`. You can then launch a HuggingFace model, say `gpt2`, in one line of code:

```python
lep photon runlocal --name gpt2 --model hf:gpt2
```

If you have access to the Llama2 model ([apply for access here](https://huggingface.co/meta-llama/Llama-2-7b)) and you have a reasonably sized GPU, you can launch it with:

```python
# hint: you can also write `-n` and `-m` for short
lep photon runlocal -n llama2 -m hf:meta-llama/Llama-2-7b-chat-hf
```

(Be sure to use the `-hf` version for Llama2, which is compatible with huggingface pipelines.)

You can then access the service with:

```python
from leptonai.client import Client, local
c = Client(local(port=8080))
# Use the following to print the doc
print(c.run.__doc__)
print(c.run(inputs="I enjoy walking with my cute dog"))
```

Fully managed Llama2 models and CodeLlama models can be found in the [playground](https://dashboard.lepton.ai/playground).

Many standard HuggingFace pipelines are supported - find out more details in the [documentation](https://www.lepton.ai/docs/advanced/prebuilt_photons#hugging-face-photons). Not all HuggingFace models are supported though, as many of them contain custom code and are not standard pipelines. If you find a popular model you would like to support, please [open an issue or a PR](https://github.com/leptonai/leptonai/issues/new).

## Checking out more examples

You can find out more examples from the [examples repository](https://github.com/leptonai/examples). For example, launch the Stable Diffusion XL model with:

```shell
git clone git@github.com:leptonai/examples.git
cd examples
```

```python
lep photon runlocal -n sdxl -m advanced/sdxl/sdxl.py
```

Once the service is running, you can access it with:
    
```python
from leptonai.client import Client, local

c = Client(local(port=8080))

img_content = c.run(prompt="a cat launching rocket", seed=1234)
with open("cat.png", "wb") as fid:
    fid.write(img_content)
```

or access the mounted Gradio UI at [http://localhost:8080/ui](http://localhost:8080/ui). Check the [README file](https://github.com/leptonai/examples/blob/main/advanced/sdxl/README.md) for more details.

A fully managed SDXL is hosted at [https://dashboard.lepton.ai/playground/sdxl](https://dashboard.lepton.ai/playground/sdxl) with API access.

## Writing your own photons

Writing your own photon is simple: write a Python Photon class and decorate functions with `@Photon.handler`. As long as your input and output are JSON serializable, you are good to go. For example, the following code launches a simple echo service:

```python
# my_photon.py
from leptonai.photon import Photon

class Echo(Photon):
    @Photon.handler
    def echo(self, inputs: str) -> str:
        """
        A simple example to return the original input.
        """
        return inputs
```

You can then launch the service with:

```shell
lep photon runlocal -n echo -m my_photon.py
```

Then, you can use your service as follows:
```python
from leptonai.client import Client, local

c = Client(local(port=8080))

# will print available paths
print(c.paths())
# will print the doc for c.echo. You can also use `c.echo?` in Jupyter.
print(c.echo.__doc__)
# will actually call echo.
c.echo(inputs="hello world")
```

For more details, checkout the [documentation](https://lepton.ai/docs/) and the [examples](https://github.com/leptonai/examples).

## Contributing

Contributions and collaborations are welcome and highly appreciated. Please check out the [contributor guide](https://github.com/leptonai/leptonai/blob/main/CONTRIBUTING.md) for how to get involved.

## License

The Lepton AI Python library is released under the Apache 2.0 license.

Developer Note: early development of LeptonAI was in a separate mono-repo, which is why you may see commits from the `leptonai/lepton` repo. We intend to use this open source repo as the source of truth going forward.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "leptonai",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "\"Lepton AI Inc.\" <dev@lepton.ai>",
    "download_url": null,
    "platform": null,
    "description": "<img src=\"https://raw.githubusercontent.com/leptonai/leptonai/main/assets/logo.svg\" height=100>\n\n# Lepton AI\n\n**A Pythonic framework to simplify AI service building**\n\n<a href=\"https://lepton.ai/\">Homepage</a> \u2022\n<a href=\"https://dashboard.lepton.ai/playground\">API Playground</a> \u2022\n<a href=\"https://github.com/leptonai/examples\">Examples</a> \u2022\n<a href=\"https://lepton.ai/docs/\">Documentation</a> \u2022\n<a href=\"https://lepton.ai/references\">CLI References</a> \u2022\n<a href=\"https://twitter.com/leptonai\">Twitter</a> \u2022\n<a href=\"https://leptonai.medium.com/\">Blog</a>\n\nThe LeptonAI Python library allows you to build an AI service from Python code with ease. Key features include:\n\n- A Pythonic abstraction `Photon`, allowing you to convert research and modeling code into a service with a few lines of code.\n- Simple abstractions to launch models like those on [HuggingFace](https://huggingface.co) in few lines of code.\n- Prebuilt examples for common models such as Llama, SDXL, Whisper, and others.\n- AI tailored batteries included such as autobatching, background jobs, etc.\n- A client to automatically call your service like native Python functions.\n- Pythonic configuration specs to be readily shipped in a cloud environment.\n\n## Getting started with one-liner\nInstall the library with:\n\n```shell\npip install -U leptonai\n```\nThis installs the `leptonai` Python library, as well as the commandline interface `lep`. You can then launch a HuggingFace model, say `gpt2`, in one line of code:\n\n```python\nlep photon runlocal --name gpt2 --model hf:gpt2\n```\n\nIf you have access to the Llama2 model ([apply for access here](https://huggingface.co/meta-llama/Llama-2-7b)) and you have a reasonably sized GPU, you can launch it with:\n\n```python\n# hint: you can also write `-n` and `-m` for short\nlep photon runlocal -n llama2 -m hf:meta-llama/Llama-2-7b-chat-hf\n```\n\n(Be sure to use the `-hf` version for Llama2, which is compatible with huggingface pipelines.)\n\nYou can then access the service with:\n\n```python\nfrom leptonai.client import Client, local\nc = Client(local(port=8080))\n# Use the following to print the doc\nprint(c.run.__doc__)\nprint(c.run(inputs=\"I enjoy walking with my cute dog\"))\n```\n\nFully managed Llama2 models and CodeLlama models can be found in the [playground](https://dashboard.lepton.ai/playground).\n\nMany standard HuggingFace pipelines are supported - find out more details in the [documentation](https://www.lepton.ai/docs/advanced/prebuilt_photons#hugging-face-photons). Not all HuggingFace models are supported though, as many of them contain custom code and are not standard pipelines. If you find a popular model you would like to support, please [open an issue or a PR](https://github.com/leptonai/leptonai/issues/new).\n\n## Checking out more examples\n\nYou can find out more examples from the [examples repository](https://github.com/leptonai/examples). For example, launch the Stable Diffusion XL model with:\n\n```shell\ngit clone git@github.com:leptonai/examples.git\ncd examples\n```\n\n```python\nlep photon runlocal -n sdxl -m advanced/sdxl/sdxl.py\n```\n\nOnce the service is running, you can access it with:\n    \n```python\nfrom leptonai.client import Client, local\n\nc = Client(local(port=8080))\n\nimg_content = c.run(prompt=\"a cat launching rocket\", seed=1234)\nwith open(\"cat.png\", \"wb\") as fid:\n    fid.write(img_content)\n```\n\nor access the mounted Gradio UI at [http://localhost:8080/ui](http://localhost:8080/ui). Check the [README file](https://github.com/leptonai/examples/blob/main/advanced/sdxl/README.md) for more details.\n\nA fully managed SDXL is hosted at [https://dashboard.lepton.ai/playground/sdxl](https://dashboard.lepton.ai/playground/sdxl) with API access.\n\n## Writing your own photons\n\nWriting your own photon is simple: write a Python Photon class and decorate functions with `@Photon.handler`. As long as your input and output are JSON serializable, you are good to go. For example, the following code launches a simple echo service:\n\n```python\n# my_photon.py\nfrom leptonai.photon import Photon\n\nclass Echo(Photon):\n    @Photon.handler\n    def echo(self, inputs: str) -> str:\n        \"\"\"\n        A simple example to return the original input.\n        \"\"\"\n        return inputs\n```\n\nYou can then launch the service with:\n\n```shell\nlep photon runlocal -n echo -m my_photon.py\n```\n\nThen, you can use your service as follows:\n```python\nfrom leptonai.client import Client, local\n\nc = Client(local(port=8080))\n\n# will print available paths\nprint(c.paths())\n# will print the doc for c.echo. You can also use `c.echo?` in Jupyter.\nprint(c.echo.__doc__)\n# will actually call echo.\nc.echo(inputs=\"hello world\")\n```\n\nFor more details, checkout the [documentation](https://lepton.ai/docs/) and the [examples](https://github.com/leptonai/examples).\n\n## Contributing\n\nContributions and collaborations are welcome and highly appreciated. Please check out the [contributor guide](https://github.com/leptonai/leptonai/blob/main/CONTRIBUTING.md) for how to get involved.\n\n## License\n\nThe Lepton AI Python library is released under the Apache 2.0 license.\n\nDeveloper Note: early development of LeptonAI was in a separate mono-repo, which is why you may see commits from the `leptonai/lepton` repo. We intend to use this open source repo as the source of truth going forward.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Lepton AI Platform",
    "version": "0.22.8",
    "project_urls": {
        "Homepage": "https://lepton.ai"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bc06c2aac80005368713767b278dde5ddbc4073f7c3048d42583a394150d25cc",
                "md5": "5f4b5766a38dc570c62d519154de913e",
                "sha256": "df1070b9e13768818238a383fe344fdbd65bba700159c147a2ef365527abe4d6"
            },
            "downloads": -1,
            "filename": "leptonai-0.22.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f4b5766a38dc570c62d519154de913e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.8",
            "size": 2398411,
            "upload_time": "2025-02-13T01:31:59",
            "upload_time_iso_8601": "2025-02-13T01:31:59.953829Z",
            "url": "https://files.pythonhosted.org/packages/bc/06/c2aac80005368713767b278dde5ddbc4073f7c3048d42583a394150d25cc/leptonai-0.22.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-13 01:31:59",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "leptonai"
}
        
Elapsed time: 3.48603s