Skip to content

Commit

Permalink
chore: reorg package exports (#3)
Browse files Browse the repository at this point in the history
* chore: reorg package exports

* chore: move model types from main

* chore: update changelog
  • Loading branch information
drochetti authored Nov 6, 2023
1 parent e4ff551 commit 59d0a5c
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 53 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## v0.2.1

### What's Changed
* chore: reorg package exports by @drochetti in https://github.com/fal-ai/serverless-client-dart/pull/3

**Full Changelog**: https://github.com/fal-ai/serverless-client-dart/compare/v0.2.0...v0.2.1

---

## v0.2.0

### What's Changed
Expand Down
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,28 @@ This client library is crafted as a lightweight layer atop platform standards li
2. Setup the client instance:

```dart
import 'package:fal_client/client.dart';
import "package:fal_client/client.dart";
final fal = FalClient.withCredentials('FAL_KEY_ID:FAL_KEY_SECRET');
final fal = FalClient.withCredentials("FAL_KEY_ID:FAL_KEY_SECRET");
```

3. Now use `fal.subcribe` to dispatch requests to the model API:

```dart
final result = await fal.subscribe('text-to-image', input: {
'prompt': 'a cute shih-tzu puppy',
'model_name': 'stabilityai/stable-diffusion-xl-base-1.0',
});
final result = await fal.subscribe('110602490-lora',
input: {
'prompt': 'a cute shih-tzu puppy',
'model_name': 'stabilityai/stable-diffusion-xl-base-1.0',
'image_size': 'square_hd'
},
onQueueUpdate: (update) => {print(update)}
);
```

**Notes:**

- Replace `text-to-image` with a valid model id. Check [fal.ai/models](https://fal.ai/models) for all available models.
- The result type is a `Map<String, dynamic>` and the entries depend on the API output schema.
- Types in Python are mapped to their corresponding types in Dart (e.g. `str` -> `String`).

## Roadmap

Expand Down
56 changes: 14 additions & 42 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:fal_client/client.dart';
import 'package:fal_client/fal_client.dart';
import 'package:flutter/material.dart';

import 'types.dart';

// You can use the proxyUrl to protect your credentials in production.
// final fal = FalClient.withProxy("http://localhost:3333/api/fal/proxy");
// final fal = FalClient.withProxy('http://localhost:3333/api/_fal/proxy');

// You can also use the credentials locally for development, but make sure
// you protected your credentials behind a proxy in production.
final fal = FalClient.withCredentials("fal_key_id:fal_key_secret");
final fal = FalClient.withCredentials('FAL_KEY_ID:FAL_KEY_SECRET');

void main() {
runApp(const MyApp());
Expand All @@ -29,38 +31,6 @@ class MyApp extends StatelessWidget {
}
}

class TextToImageResult {
final List<ImageRef> images;
final int seed;

TextToImageResult({required this.images, required this.seed});

factory TextToImageResult.fromMap(Map<String, dynamic> json) {
return TextToImageResult(
images: (json['images'] as List<dynamic>)
.map((e) => ImageRef.fromMap(e as Map<String, dynamic>))
.toList(),
seed: json['seed'],
);
}
}

class ImageRef {
final String url;
final int height;
final int width;

ImageRef({required this.url, required this.height, required this.width});

factory ImageRef.fromMap(Map<String, dynamic> json) {
return ImageRef(
url: json['url'],
height: json['height'],
width: json['width'],
);
}
}

class TextoToImageScreen extends StatefulWidget {
const TextoToImageScreen({super.key, required this.title});

Expand All @@ -71,7 +41,7 @@ class TextoToImageScreen extends StatefulWidget {
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
// always marked 'final'.

final String title;

Expand All @@ -82,19 +52,21 @@ class TextoToImageScreen extends StatefulWidget {
class _TextoToImageScreenState extends State<TextoToImageScreen> {
bool _isLoading = false;
final _promptController =
TextEditingController(text: "a cute shih-tzu puppy");
TextEditingController(text: 'a cute shih-tzu puppy');
ImageRef? _image;

void _generateImage() async {
setState(() {
_isLoading = true;
_image = null;
});
final result = await fal.subscribe("110602490-lora", input: {
"prompt": _promptController.text,
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
"image_size": "square_hd"
});
final result = await fal.subscribe(textToImageId,
input: {
'prompt': _promptController.text,
'model_name': 'stabilityai/stable-diffusion-xl-base-1.0',
'image_size': 'square_hd'
},
onQueueUpdate: (update) => {print(update)});
setState(() {
_isLoading = false;
_image = TextToImageResult.fromMap(result).images[0];
Expand Down
33 changes: 33 additions & 0 deletions example/lib/types.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class TextToImageResult {
final List<ImageRef> images;
final int seed;

TextToImageResult({required this.images, required this.seed});

factory TextToImageResult.fromMap(Map<String, dynamic> json) {
return TextToImageResult(
images: (json['images'] as List<dynamic>)
.map((e) => ImageRef.fromMap(e as Map<String, dynamic>))
.toList(),
seed: (json['seed'] * 1).round(),
);
}
}

class ImageRef {
final String url;
final int height;
final int width;

ImageRef({required this.url, required this.height, required this.width});

factory ImageRef.fromMap(Map<String, dynamic> json) {
return ImageRef(
url: json['url'],
height: (json['height'] * 1).round(),
width: (json['width'] * 1).round(),
);
}
}

const textToImageId = '110602490-lora';
5 changes: 5 additions & 0 deletions lib/fal_client.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export 'src/client.dart';
export 'src/config.dart';
export 'src/exception.dart';
export 'src/queue.dart';
export 'src/storage.dart';
1 change: 0 additions & 1 deletion lib/runtime/version.dart

This file was deleted.

2 changes: 0 additions & 2 deletions lib/client.dart → lib/src/client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library fal_client;

import './config.dart';
import './exception.dart';
import './http.dart';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions lib/src/runtime/version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Note: temporary solution, should be replaced with something
// else that resolves the package version at build-time or runtime.
const packageVersion = '0.2.1';
File renamed without changes.
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: fal_client
description: >
The Dart client library for fal.ai model APIs.
You can use it to call multiple AI models on your Dart and Flutter apps.
version: 0.2.0
version: 0.2.1
homepage: https://fal.ai
repository: https://github.com/fal-ai/serverless-client-dart
issue_tracker: https://github.com/fal-ai/serverless-client-dart/issues?q=is%3Aissue+is%3Aopen
Expand Down

0 comments on commit 59d0a5c

Please sign in to comment.