replicate-swift icon indicating copy to clipboard operation
replicate-swift copied to clipboard

enum Predictable

Open tonyljx opened this issue 1 year ago • 1 comments

Hi there

I am reading https://replicate.com/docs/guides/swiftui to use swiftui replicate sdk to call the model.

And i find out that some models do not have the version on web page.

Question1

  1. Which method do you recommend if I need to use different replicate models?

seems like in getModel Method, I will use multiple if else because different models need different input

enum StableDiffusion: Predictable {
  static var modelID = "stability-ai/stable-diffusion"
  static let versionID = "db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf"
 
  struct Input: Codable {
      let prompt: String
  }
 
  typealias Output = [URL]
}

or

let model = try await replicate.getModel("stability-ai/stable-diffusion-3")
if let latestVersion = model.latestVersion {
    let prompt = "a 19th century portrait of a gentleman otter"
    let prediction = try await replicate.createPrediction(version: latestVersion.id,
                                                       input: ["prompt": "\(prompt)"],
                                                       wait: true)
    print(prediction.id)
    // "s654jhww3hrm60ch11v8t3zpkg"
    print(prediction.output)
    // ["https://replicate.delivery/yhqm/bh9SsjWXY3pGKJyQzYjQlsZPzcNZ4EYOeEsPjFytc5TjYeNTA/R8_SD3_00001_.webp"]
}

Question2

In enum Predictable, how can I receive input image?

tonyljx avatar Oct 13 '24 10:10 tonyljx

I think it's same principle as node-based API, you listen to prediction and when it's ready you get the image?

romanr avatar May 12 '25 16:05 romanr