承接 imactool/hyperf-stable-diffusion 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

imactool/hyperf-stable-diffusion

Composer 安装命令:

composer require imactool/hyperf-stable-diffusion

包简介

hyperf-stable-diffusion

README 文档

README

基于 rulilg/laravel-stable-diffusion 包直接平移并适配了 hyperf 框架。

我对它进行了一些改造,大部分功能保持了相同。在这里感谢一下 RuliLG ,实现了如此强大好用的 stable-diffusion 组件。

基于 Replicate API 和 stablediffusionapi 的 Stable Diffusion 实现。

  • 🎨 Built-in prompt helper to create better images
  • 🚀 Store the results in your database
  • 🎇 Generate multiple images in the same API call
  • 💯 Supports both (text to image) and (image to image)

鸣谢:原作:RuliLG,特此鸣谢!

安装

composer require imactool/hyperf-stable-diffusion

注意 表新增了platform平台字段。-- 后续会使用迁移增加,目前不考虑 :)

发布配置(包含配置文件和迁移文件)

php bin/hyperf.php vendor:publish imactool/hyperf-stable-diffusion
php bin/hyperf.php migrate

至此,配置完成。

return [
    'url' => env('REPLICATE_URL', 'https://api.replicate.com/v1/predictions'),
    'token' => env('REPLICATE_TOKEN'),
    'version' => env('REPLICATE_STABLEDIFFUSION_VERSION', 'db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf'),
];

然后在 .env 里增加 ReplicatetokenREPLICATE_TOKEN即可。

使用

文字生成图片(Text to Image)

use Imactool\HyperfStableDiffusion\Prompt;
use Imactool\HyperfStableDiffusion\Replicate;

   $result = Replicate::make()->withPrompt(
            Prompt::make()
                ->with('a panda sitting on the streets of New York after a long day of walking')
                ->photograph()
                ->resolution4k()
                ->trendingOnArtStation()
                ->highlyDetailed()
                ->dramaticLighting()
                ->octaneRender()
        )->inputParams('num_outputs', 1)
        ->generate(); //根据不同的模型来传递生成的张数

图片生成图片(Image to Image)

use Imactool\HyperfStableDiffusion\Prompt;
use Imactool\HyperfStableDiffusion\Replicate;
use Intervention\Image\ImageManager;

//这里使用了 intervention/image 扩展来处理图片文件,你也可以更换为其他的
 $sourceImg =  (string) (new ImageManager(['driver' => 'imagick']))->make('path/image/source.png')->encode('data-url');

$prompt = 'Petite 21-year-old Caucasian female gamer streaming from her bedroom with pastel pink pigtails and gaming gear. Dynamic and engaging image inspired by colorful LED lights and the energy of Twitch culture, in 1920x1080 resolution.';
$result = Replicate::make()
    ->converVersion('a991dcab77024471af6a89ef758d98d1a54c5a25fc52a06ccfd7754b7ad04b35')
    ->withPrompt(
        Prompt::make()
            ->with($prompt)
    )
    ->inputParams('image',$sourceImg)
    ->inputParams('negative_prompt', 'disfigured, kitsch, ugly, oversaturated, greain, low-res, Deformed, blurry, bad anatomy, disfigured, poorly drawn face, mutation, mutated, extra limb, ugly, poorly drawn hands, missing limb, blurry, floating limbs, disconnected limbs, malformed hands, blur, out of focus, long neck, long body, ugly, disgusting, poorly drawn, childish, mutilated, mangled, old, surreal, calligraphy, sign, writing, watermark, text, body out of frame, extra legs, extra arms, extra feet, out of frame, poorly drawn feet, cross-eye, blurry, bad anatomy')
    ->inputParams('strength', 0.5)
    ->inputParams('upscale', 2)
    ->inputParams('num_inference_steps', 25)
    ->inputParams('guidance_scale', 7.5)
    ->inputParams('scheduler', 'EulerAncestralDiscrete')
    ->inputParams('num_outputs', 1)
    ->generate();

查询结果

use Imactool\HyperfStableDiffusion\Replicate;
 $freshResults = Replicate::get($replicate_id);

Generating prompts

There are several styles already built-in:

Method Prompt modification
realistic() {prompt}, realistic
hyperrealistic() {prompt}, hyperrealistic
conceptArt() {prompt}, concept art
abstractArt() {prompt}, abstract art
oilPainting() {prompt}, oil painting
watercolor() {prompt}, watercolor
acrylic() {prompt}, acrylic
pencilDrawing() {prompt}, pencil drawing
digitalPainting() {prompt}, digital painting
penDrawing() {prompt}, pen drawing
charcoalDrawing() {prompt}, charcoal drawing
byPicasso() {prompt}, by Pablo Picasso
byVanGogh() {prompt}, by Vincent Van Gogh
byRembrandt() {prompt}, by Rembrandt
byMunch() {prompt}, by Edvard Munch
byKlimt() {prompt}, by Paul Klimt
byKandinsky() {prompt}, by Jackson Pollock
byMonet() {prompt}, by Claude Monet
byDali() {prompt}, by Salvador Dali
byDegas() {prompt}, by Edgar Degas
byKahlo() {prompt}, by Frida Kahlo
byCezanne() {prompt}, by Pablo Cezanne
photograph() a photo of {prompt}
highlyDetailed() {prompt}, highly detailed
surrealism() {prompt}, surrealism
trendingOnArtStation() {prompt}, trending on art station
triadicColorScheme() {prompt}, triadic color scheme
smooth() {prompt}, smooth
sharpFocus() {prompt}, sharp focus
matte() {prompt}, matte
elegant() {prompt}, elegant
theMostBeautifulImageEverSeen() {prompt}, the most beautiful image ever seen
illustration() {prompt}, illustration
digitalPaint() {prompt}, digital paint
dark() {prompt}, dark
gloomy() {prompt}, gloomy
octaneRender() {prompt}, octane render
resolution8k() {prompt}, 8k
resolution4k() {prompt}, 4k
washedColors() {prompt}, washed colors
sharp() {prompt}, sharp
dramaticLighting() {prompt}, dramatic lighting
beautiful() {prompt}, beautiful
postProcessing() {prompt}, post processing
pictureOfTheDay() {prompt}, picture of the day
ambientLighting() {prompt}, ambient lighting
epicComposition() {prompt}, epic composition

Additionally, you can add custom styles with the following methods:

  • as(string $canvas): to add a string at the beginning (i.e. "a photograph of")
  • paintingStyle(string $style): to add a painting style (i.e. realistic, hiperrealistic, etc.)
  • by(string $author): to instruct the system to paint it with the style of a certain author
  • effect(string $effect): to add a finishing touch to the prompt. You can add as many as you want.

To learn more on how to build prompts for Stable Diffusion, please enter this link.

基于 stablediffusionapi 平台 https://stablediffusionapi.com/docs/

或者 Postman Collection

文字生成图片(Text to Image)

use Imactool\HyperfStableDiffusion\StableDiffusion;

 $res = StableDiffusion::make()
                    ->useDreamboothApiV4()
                    ->withPayload('key', '')
                    ->withPayload('model_id', 'anything-v4')
                    ->withPayload('prompt', 'ultra realistic close up portrait ((beautiful pale cyberpunk female with heavy black eyeliner)), blue eyes, shaved side haircut, hyper detail, cinematic lighting, magic neon, dark red city, Canon EOS R3, nikon, f/1.4, ISO 200, 1/160s, 8K, RAW, unedited, symmetrical balance, in-frame, 8K')
                    ->withPayload('negative_prompt', 'painting, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, deformed, ugly, blurry, bad anatomy, bad proportions, extra limbs, cloned face, skinny, glitchy, double torso, extra arms, extra hands, mangled fingers, missing lips, ugly face, distorted face, extra legs, anime')
                    ->withPayload('width', '512')
                    ->withPayload('height', '512')
                    ->withPayload('samples', '1')
                    ->withPayload('num_inference_steps', '30')
                    ->withPayload('seed', null)
                    ->withPayload('guidance_scale', '7.5')
                    ->withPayload('webhook', null)
                    ->withPayload('track_id', null)
                    ->text2img();

                var_dump( $res);

License

The MIT License (MIT). Please see License File for more information.

imactool/hyperf-stable-diffusion 适用场景与选型建议

imactool/hyperf-stable-diffusion 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 139 次下载、GitHub Stars 达 6, 最近一次更新时间为 2023 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 imactool/hyperf-stable-diffusion 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-15