定制 modelslab/php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

modelslab/php

Composer 安装命令:

composer require modelslab/php

包简介

PHP SDK for ModelsLab API - AI-powered image, video, audio, and 3D generation services

README 文档

README

A PHP SDK for the ModelsLab API, providing easy access to AI-powered image, video, audio, and 3D generation services.

Installation

Install the SDK using Composer:

composer require modelslab/php

Or add it to your composer.json:

{
    "require": {
        "modelslab/php": "^1.0.2"
    }
}

Quick Start

Text to Speech

<?php
require_once 'vendor/autoload.php';

use ModelsLab\ModelsLab;
use ModelsLab\Schemas\Text2Speech;

$apiKey = 'your-api-key';
$modelslab = new ModelsLab($apiKey);

$tts = new Text2Speech([
    'prompt' => 'Hello from ModelsLab!',
    'voice_id' => 'madison',
    'language' => 'english'
]);

$response = $modelslab->audio()->textToSpeech($tts);
echo json_encode($response, JSON_PRETTY_PRINT);

Text to Image

<?php
require_once 'vendor/autoload.php';

use ModelsLab\ModelsLab;
use ModelsLab\Schemas\RealtimeText2ImageSchema;

$apiKey = 'your-api-key';
$modelslab = new ModelsLab($apiKey);

$image = new RealtimeText2ImageSchema([
    'prompt' => 'A beautiful landscape',
    'width' => 512,
    'height' => 512
]);

$response = $modelslab->realtime()->textToImage($image);
echo json_encode($response, JSON_PRETTY_PRINT);

Text to Video

<?php
require_once 'vendor/autoload.php';

use ModelsLab\ModelsLab;
use ModelsLab\Schemas\Text2Video;

$apiKey = 'your-api-key';
$modelslab = new ModelsLab($apiKey);

$video = new Text2Video([
    'prompt' => 'A cat playing with a ball',
    'model_id' => 'svd'
]);

$response = $modelslab->video()->textToVideo($video);
echo json_encode($response, JSON_PRETTY_PRINT);

Deepfake Video Swap

<?php
require_once 'vendor/autoload.php';

use ModelsLab\ModelsLab;
use ModelsLab\Schemas\DeepfakeSchema;

$apiKey = 'your-api-key';
$modelslab = new ModelsLab($apiKey);

$deepfake = new DeepfakeSchema([
    'init_image' => 'https://example.com/face.jpg',
    'init_video' => 'https://example.com/video.mp4',
    'output_format' => 'mp4'
]);

$response = $modelslab->deepfake()->singleVideoSwap($deepfake);
echo json_encode($response, JSON_PRETTY_PRINT);

API Reference

Audio API

The Audio API provides text-to-speech, music generation, and voice conversion capabilities.

$audio = $modelslab->audio();

// Text to Speech
$response = $audio->textToSpeech($textToSpeechSchema);

// Music Generation
$response = $audio->musicGen($musicGenSchema);

// Voice to Voice
$response = $audio->voice2Voice($voice2VoiceSchema);

// Sound Effects
$response = $audio->sfxGen($sfxSchema);

Video API

Generate videos from text prompts.

$video = $modelslab->video();

// Text to Video
$response = $video->textToVideo($videoSchema);

// Image to Video
$response = $video->imageToVideo($imageToVideoSchema);

// Text to Video Ultra
$response = $video->textToVideoUltra($text2VideoUltraSchema);

// Watermark Remover - Remove watermarks from videos
$watermarkRemover = new WatermarkRemoverSchema([
    'key' => $apiKey,
    'init_video' => 'https://example.com/video.mp4'
]);
$response = $video->watermarkRemover($watermarkRemover);

3D API

Generate 3D models from text descriptions.

$threeD = $modelslab->threeD();
$response = $threeD->textTo3D($threeDSchema);

Interior API

Generate interior design images.

$interior = $modelslab->interior();

// Interior Design
$response = $interior->makeInterior($interiorSchema);

// Room Decorator
$response = $interior->roomDecorator($roomDecoratorSchema);

// Floor Planning
$response = $interior->floorPlanning($floorPlanningSchema);

// Sketch Rendering
$response = $interior->sketchRendering($sketchRenderingSchema);

// Object Removal - Remove objects from room images
$objectRemoval = new ObjectRemovalSchema([
    'key' => $apiKey,
    'init_image' => 'https://example.com/room.jpg',
    'object_name' => 'chair',
    'base64' => false
]);
$response = $interior->objectRemoval($objectRemoval);

// Interior Mixer - Add objects from one image into another room
$interiorMixer = new InteriorMixerSchema([
    'key' => $apiKey,
    'init_image' => 'https://example.com/room.jpg',
    'object_image' => 'https://example.com/furniture.jpg',
    'prompt' => 'Add the furniture to the living room',
    'width' => 1280,
    'height' => 1280,
    'num_inference_steps' => 8,
    'base64' => false
]);
$response = $interior->interiorMixer($interiorMixer);

Realtime API

Real-time image generation.

$realtime = $modelslab->realtime();
$response = $realtime->textToImage($realtimeSchema);

Deepfake API

Generate deepfake content.

$deepfake = $modelslab->deepfake();
$response = $deepfake->generate($deepfakeSchema);

Community API

Access community models.

$community = $modelslab->community();
$response = $community->generate($communitySchema);

Image Editing API

Edit and manipulate images.

$imageEditing = $modelslab->imageEditing();

// Qwen Edit - Edit images using Qwen model
$qwenEdit = new QwenEditSchema([
    'key' => $apiKey,
    'prompt' => 'Add a sunset in the background',
    'init_image' => ['https://example.com/image1.jpg', 'https://example.com/image2.jpg'],
    'base64' => false
]);
$response = $imageEditing->qwenEdit($qwenEdit);

// Caption - Generate captions for images
$caption = new CaptionSchema([
    'key' => $apiKey,
    'init_image' => 'https://example.com/image.jpg',
    'length' => 'normal', // 'short', 'normal', or 'long'
    'base64' => false
]);
$response = $imageEditing->caption($caption);

// Other image editing methods
$response = $imageEditing->backgroundRemover($backgroundRemoverSchema);
$response = $imageEditing->superResolution($superResolutionSchema);
$response = $imageEditing->outpainting($outpaintingSchema);
$response = $imageEditing->inpainting($inpaintingSchema);
$response = $imageEditing->objectRemover($objectRemoverSchema);
$response = $imageEditing->facegen($facegenSchema);
$response = $imageEditing->headshot($headshotSchema);
$response = $imageEditing->fashion($fashionSchema);

Configuration

Environment Variables

You can set your API key using environment variables:

export MODELSLAB_API_KEY="your-actual-api-key"

Or use the API_KEY environment variable:

export API_KEY="your-actual-api-key"

Client Options

$modelslab = new ModelsLab($apiKey, [
    'base_url' => 'https://modelslab.com/api/',
    'fetch_retry' => 10,
    'fetch_timeout' => 2
]);

Error Handling

The SDK throws exceptions for various error conditions:

try {
    $response = $modelslab->audio()->textToSpeech($schema);
} catch (InvalidArgumentException $e) {
    // Invalid API key or parameters
    echo "Invalid argument: " . $e->getMessage();
} catch (RuntimeException $e) {
    // Network or API errors
    echo "Request failed: " . $e->getMessage();
}

Environment Setup

  1. Copy the environment example file:
cp env.example .env
  1. Edit .env and add your API key:
MODELSLAB_API_KEY=your-actual-api-key

Requirements

  • PHP 7.4 or higher
  • Guzzle HTTP client
  • Composer for dependency management

License

MIT License

Support

For support and questions, please contact support@modelslab.com or visit our documentation.

modelslab/php 适用场景与选型建议

modelslab/php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「sdk」 「text-to-speech」 「ai」 「machine-learning」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 modelslab/php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 modelslab/php 我们能提供哪些服务?
定制开发 / 二次开发

基于 modelslab/php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-24