Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

It's a swift layer between Replicate API and your swiftui application. Replicate toolkit for running text to image model, stable difusion model, ML makeovers, super resolution, diffusion api library for swift, client for using diffusion in real-time applications Integration example swiftui

License

NotificationsYou must be signed in to change notification settings

swiftuiux/replicate-kit-swift

Repository files navigation

It is not official toolkit for swift from Replicate I do it because I'd like to support guys who are creating open-source models for Replicate

SwiftUI example for the package

Replicate kit example app

The concept

Replicate is a service that lets you run machine learning models with a few lines of code, without needing to understand how machine learning works. This package is the swift layer between Replicate API and your application.

How to use

Authentication

All API requests must be authenticated with a token.Get your API key

leturl=URL(string:ReplicateAPI.Endpoint.baseURL)letapiKey="your API key"        api=ReplicateAPI(baseURL: url, apiKey: apiKey)

Get a model

  • owner - The name of the user or organization that owns the model
  • name - The name of the model
letmodel=tryawait api.getModel(owner: item.owner, name: item.name)

Create prediction and get result

Calling this operation starts a new prediction for the version and inputs you provide. As models can take several seconds or more to run, the output will not be available immediately. To get the final result of the prediction you should either provide a webhook URL to call when the results are ready, or wait a prediction result until it has one of the finished statuses.

guardlet latest= model.latestVersionelse{throwErrors.latestVersionIsEmpty}    /// In the case of success, output will be an object containing the     ///  output of the model. Any files will be represented as URLs.letoutput:[String]?=tryawait api.createPrediction(            version: latest.id,            input: input.params /// ["prompt": "an astronaut riding a horse on mars"]).output
"output": ["https://replicate.com/api/models/stability-ai/stable-diffusion/files/9c3b6fe4-2d37-4571-a17a-83951b1cb120/out-0.png"  ]

Each time a prediction generates an output (note that predictions can generate multiple outputs)You can find input format for models atthe model page for example

Handling errors

Processing a response errors cases when server cannot or will not process the request due to something that is perceived to be a client errorThe concept

Replicate API

    /// Get a collection of models    /// - Parameter collection_slug: The slug of the collection, like    /// super-resolution or image-restoration    /// - Returns: a collection of modelspublicfunc getCollections(collection_slug:String)asyncthrows->CollectionOfModels
    /// Get a model    /// - Parameters:    ///   - owner: Model owner    ///   - name: Model namepublicfunc getModel(owner:String, name:String)asyncthrows->Model
    /// Create prediction    /// - Parameters:    ///   - versionId: Version id    ///   - input: Input data    ///   - expect: Logic for awaiting a prediction check out ``ReplicateAPI.Expect``    ///  - webhook: An HTTPS URL for receiving a webhook when the prediction has new output.    /// - Returns: Prediction resultpublicfunc createPrediction<Input:Encodable, Output:Decodable>(        version id:String,        input:Input,        expect:Expect=.yes(),        webhook:URL?=nil)asyncthrows->Prediction<Output>
    /// Get prediction    /// Returns the same response as the create a prediction operation    /// status will be one of ``Prediction.Status``    /// In the case of success, output will be an object containing the output    /// of the model. Any files will be represented as URLs.    /// - Parameter id: Prediction id    /// - Returns: Predictionpublicfunc getPrediction<Output:Decodable>(        by id:String)asyncthrows->Prediction<Output>

The concept

Documentation(API)

  • You need to have Xcode 13 installed in order to have access to Documentation Compiler (DocC)
  • Go to Product > Build Documentation or⌃⇧⌘ D

The concept

About

It's a swift layer between Replicate API and your swiftui application. Replicate toolkit for running text to image model, stable difusion model, ML makeovers, super resolution, diffusion api library for swift, client for using diffusion in real-time applications Integration example swiftui

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp