Skip to main content

No project description provided

Project description

FlyMy.AI

Generated with FlyMy.AI in 🚀 70ms
Generated with FlyMy.AI in 🚀 70ms

Welcome to FlyMy.AI inference platform. Our goal is to provide the fastest and most affordable deployment solutions for neural networks and AI applications.

  • Fast Inference: Experience the fastest Stable Diffusion inference globally.
  • Scalability: Autoscaling to millions of users per second.
  • Ease of Use: One-click deployment for any publicly available neural networks.

Website

For more information, visit our website: FlyMy.AI Or connect with us and other users on Discord: Join Discord

Getting Started

This is a Python client for FlyMyAI. It allows you to easily run models and get predictions from your Python code in sync and async mode.

Requirements

  • Python 3.8+

Installation

Install the FlyMyAI client using pip:

pip install flymyai

Authentication

Before using the client, you need to have your API key, username, and project name. In order to get credentials, you have to sign up on flymy.ai and get your personal data on the profile.

Basic Usage

Here's a simple example of how to use the FlyMyAI client:

BERT Sentiment analysis

import flymyai

response = flymyai.run(
    apikey="fly-secret-key",
    model="flymyai/bert",
    payload={"text": "What a fabulous fancy building! It looks like a palace!"}
)
print(response.output_data["logits"][0])

Sync Streams

For llms you should use stream method

llama 3.1 8b

from flymyai import client, FlyMyAIPredictException

fma_client = client(apikey="fly-secret-key")

stream_iterator = fma_client.stream(
    payload={
        "prompt": "tell me a story about christmas tree",
        "best_of": 12,
        "max_tokens": 1024,
        "stop": 1,
        "temperature": 1,
        "top_k": 1,
        "top_p": "0.95",
    },
    model="flymyai/llama-v3-1-8b"
)
try:
    for response in stream_iterator:
        if response.output_data.get("output"):
            print(response.output_data["output"].pop(), end="")
except FlyMyAIPredictException as e:
    print(e)
    raise e
finally:
    print()
    print(stream_iterator.stream_details)

Async Streams

For llms you should use stream method

Stable Code Instruct 3b

import asyncio

from flymyai import async_client, FlyMyAIPredictException


async def run_stable_code():
    fma_client = async_client(apikey="fly-secret-key")
    stream_iterator = fma_client.stream(
        payload={
            "prompt": "What's the difference between an iterator and a generator in Python?",
            "best_of": 12,
            "max_tokens": 512,
            "stop": 1,
            "temperature": 1,
            "top_k": 1,
            "top_p": "0.95",
        },
        model="flymyai/Stable-Code-Instruct-3b"
    )
    try:
        async for response in stream_iterator:
            if response.output_data.get("output"):
                print(response.output_data["output"].pop(), end="")
    except FlyMyAIPredictException as e:
        print(e)
        raise e
    finally:
        print()
        print(stream_iterator.stream_details)


asyncio.run(run_stable_code())

File Inputs

ResNet image classification

You can pass file inputs to models using file paths:

import pathlib

import flymyai

response = flymyai.run(
    apikey="fly-secret-key",
    model="flymyai/resnet",
    payload={"image": pathlib.Path("/path/to/image.png")}
)
print(response.output_data["495"])

File Response Handling

Files received from the neural network are always encoded in base64 format. To process these files, you need to decode them first. Here's an example of how to handle an image file:

StableDiffusion Turbo image generation in ~50ms 🚀

import base64
import flymyai

response = flymyai.run(
    apikey="fly-secret-key",
    model="flymyai/SDTurboFMAAceleratedH100",
    payload={
        "prompt": "An astronaut riding a rainbow unicorn, cinematic, dramatic, photorealistic",
    }
)
base64_image = response.output_data["sample"][0]
image_data = base64.b64decode(base64_image)
with open("generated_image.jpg", "wb") as file:
    file.write(image_data)

Asynchronous Requests

FlyMyAI supports asynchronous requests for improved performance. Here's how to use it:

import asyncio
import flymyai


async def main():
    payloads = [
        {
            "prompt": "An astronaut riding a rainbow unicorn, cinematic, dramatic, photorealistic",
            "negative_prompt": "Dark colors, gloomy atmosphere, horror",
            "seed": count,
            "denoising_steps": 4,
            "scheduler": "DPM++ SDE"
         }
        for count in range(1, 10)
    ]
    async with asyncio.TaskGroup() as gr:
        tasks = [
            gr.create_task(
                flymyai.async_run(
                    apikey="fly-secret-key",
                    model="flymyai/DreamShaperV2-1",
                    payload=payload
                )
            )
            for payload in payloads
        ]
    results = await asyncio.gather(*tasks)
    for result in results:
        print(result.output_data["output"])


asyncio.run(main())

Running Models in the Background

To run a model in the background, simply use the async_run() method:

import asyncio
import flymyai
import pathlib


async def background_task():
    payload = {"audio": pathlib.Path("/path/to/audio.mp3")}
    response = await flymyai.async_run(
        apikey="fly-secret-key",
        model="flymyai/whisper",
        payload=payload
    )
    print("Background task completed:", response.output_data["transcription"])


async def main():
    task = asyncio.create_task(background_task())
    await task

asyncio.run(main())
# Continue with other operations while the model runs in the background

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flymyai-1.0.19.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

flymyai-1.0.19-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file flymyai-1.0.19.tar.gz.

File metadata

  • Download URL: flymyai-1.0.19.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1024-azure

File hashes

Hashes for flymyai-1.0.19.tar.gz
Algorithm Hash digest
SHA256 58442659a9a690430b14857272f342830d301554847a9c6be4d538671b618e6e
MD5 7ea24ae666d7cefb16dacc173ac749db
BLAKE2b-256 b2a582ce2d2b104b5947f1ac06d7a9264c5d89475316efaf5da8aa85fdaf0ecf

See more details on using hashes here.

File details

Details for the file flymyai-1.0.19-py3-none-any.whl.

File metadata

  • Download URL: flymyai-1.0.19-py3-none-any.whl
  • Upload date:
  • Size: 19.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.5.0-1024-azure

File hashes

Hashes for flymyai-1.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 80aa93f6c34eca1cc9b5dd8f46ee2e753b677014045bf57da7ce3a35537d1268
MD5 2941b0299dd8ee5dc8d8023739693a03
BLAKE2b-256 763519ac2770d9324edfa92a4b3b743a81fc0691e8b187dabcad2aebcad8937c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page