Giter Site home page Giter Site logo

ramnatht / openai-async-image-swiftui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from the-igor/openai-async-image-swiftui

0.0 0.0 0.0 2.89 MB

OpenAI AsyncImage for SwiftUI Just type in a text description of the desired image Swift

License: MIT License

Swift 100.00%

openai-async-image-swiftui's Introduction

OpenAI AsyncImage SwiftUI

SwiftUI view that asynchronously loads and displays an OpenAI image from open API

Features

  • Multiplatform iOS, macOS and watchOS
  • Customizable in term of SwiftUI Image specs [renderingMode, resizable, antialiased...]
  • Customizable in term of the transport layer [Loader]
  • Based on interfaces not implementations

OpenAI AsyncImage SwiftUI

How to use

1. Get your API key from OpenAI

Where do I find my Secret API Key?

2. Override the default loader at Environment with you apiKey

@Environment(\.openAIDefaultLoader) var loader : OpenAIDefaultLoader

let apiKey = "*******************"
let endpoint = OpenAIImageEndpoint.get(with: apiKey)
let loader = OpenAIDefaultLoader(endpoint: endpoint)

 ContentView()
        .environment(\.openAIDefaultLoader, loader)

3. Add OpenAIAsyncImage to your code

OpenAIAsyncImage(prompt: .constant("sun"))
               .frame(width: 125, height: 125)

or with custom ViewBuilder

OpenAIAsyncImage(prompt: $imageText, size: .dpi1024){ state in
    switch state{
        case .loaded(let image) :
        image
            .resizable()
            .scaledToFill()
        case .loadError(let error) : Text(error.localizedDescription)
        case .loading : ProgressView()
    }
}
Param Description
prompt A text description of the desired image(s). The maximum length is 1000 characters
size The size of the generated images. Must be one of 256x256, 512x512, or 1024x1024
tpl Custom view builder tpl
loader Custom loader if you need something specific

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

SwiftUI example for the package

OpenAI AsyncImage SwiftUI example

OpenAI AsyncImage SwiftUI

openai-async-image-swiftui's People

Contributors

the-igor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.