Skip to main content

Examples

Nano-banana on CPU​

from typing import List, Optional

from pydantic import BaseModel

from fma.toolkit import model as fma_model
from fma.toolkit.fields.image import Image


class Input(BaseModel):
prompt: str
image: Optional[Image]
image1: Optional[Image]


class Output(BaseModel):
sample: Image


class Model(fma_model.Model):
requirements: List[str] = ["git+https://<token>@github.com/FlyMyAI/flymy_nano_banana.git"]

def initialize(self):
import os

os.environ['GOOGLE_API_KEY'] = ''
os.environ['MODEL'] = 'gemini-2.5-flash-image-preview'

from flymy_nano_banana.image_generator import GoogleImageGenerator

self.image_generator = GoogleImageGenerator()

def predict(self, input: Input) -> Output:
prompt = input["prompt"]
image = input["image"]
image1 = input["image1"]

generated_image = self.image_generator.generate_image(prompt, image, image1) # type: ignore
if generated_image is None:
raise ValueError("No image was generated")

return {"sample": generated_image}

LoRA Training​

This example demonstrates how to train a LoRA model using the FlyMyAI platform. The training process is asynchronous, so you'll need to poll for results.

import os

try:
import flymyai
except ModuleNotFoundError:
os.system('pip install flymyai')
import flymyai

payload = {
"lora_name": "random-lora",
"trigger_word": "random",
"dataset_url": "", # dataset might be an zip archive with jpeg photos in it
"training_steps": 1000,
}

fma_client = flymyai.client(apikey=os.getenv("FLYMYAI_API_KEY", ""))

prediction_task = fma_client.predict_async_task(
model="flymyai/flux-lora-trainer-fast",
payload=payload,
)
print(f'Got prediction task: {prediction_task}')

while True:
try:
# Get result
result = fma_client.prediction_task_result(prediction_task)
break
except:
continue

print(f"Prediction completed: {result.inference_responses}")
print(result.inference_responses[0].output_data['model'][0]['data'])
print(result.inference_responses[0].output_data['config'][0]['data'])

Parameters​

  • lora_name: Name for your LoRA model
  • trigger_word: Word to activate the LoRA model in prompts
  • dataset_url: Direct URL to your training dataset. The dataset should be a ZIP archive containing JPEG images
  • training_steps: Number of training steps (typically 1000-2000)

Notes​

  • The training process is asynchronous and may take several minutes to complete
  • Make sure your FLYMYAI_API_KEY environment variable is set
  • The dataset should be a ZIP archive containing JPEG images for training