-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
172 lines (138 loc) · 4.29 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# bfl
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
The goal of the bfl package is to simplify the creation of FLUX images using the Black Forest Labs
(BFL) API. The API provides access to endpoints for four distinct FLUX models and three FLUX tools,
enabling users to generate and manipulate high-quality images with ease. To learn more about the models,
visit [Black Forest Labs FLUX Models](https://blackforestlabs.ai/flux-1-tools/).
## Installation
You can install the development version of bfl from [GitHub](https://github.com/gacolitti/bfl) with:
``` r
# install.packages("pak")
pak::pak("gacolitti/bfl")
```
## Authentication
To use the `bfl` package, you need an API key from [Black Forest Labs](https://api.bfl.ml/auth/login).
To authenticate, define an
environment variable named `BFL_API_KEY` in your `.Renviron` file with your API key value.
For example, add the following line to your `.Renviron` file:
```
BFL_API_KEY=your_api_key_here
```
## Examples
#### FLUX Dev
```{r generating-images, eval=FALSE}
library(bfl)
library(magick)
gen_flux_dev(
prompt = "cypherpunk girl with red sunglasses, futuristic scene in the background",
prompt_upsampling = TRUE,
seed = 2
)
```
```{r, echo=FALSE}
knitr::include_graphics("inst/images/readme-flux-dev-example.jpeg")
```
#### FLUX Pro
```{r, eval=FALSE}
gen_flux_pro(
prompt = "cypherpunk girl with red sunglasses, futuristic scene in the background",
prompt_upsampling = TRUE,
seed = 1
)
```
```{r, echo=FALSE}
knitr::include_graphics("inst/images/readme-flux-pro-example.jpeg")
```
#### FLUX Pro Ultra
```{r, eval=FALSE}
gen_flux_pro1.1_ultra(
prompt = "cypherpunk girl with red sunglasses, futuristic scene in the background",
prompt_upsampling = TRUE,
seed = 1
)
```
```{r, echo=FALSE}
knitr::include_graphics("inst/images/readme-flux-pro-ultra-example.jpeg")
```
#### FLUX Fill Pro
```{r, eval=FALSE}
mask <- base64enc::base64encode(system.file("/images/backyard-original_mask.jpeg", package = "bfl"))
image <- base64enc::base64encode(system.file("/images/backyard-original.jpeg", package = "bfl"))
res <- bfl::gen_flux_fill_pro1(
image = image,
mask = mask,
prompt = "alien spaceship, ultrarealistic, detailed",
seed = 200,
steps = 50,
prompt_upsampling = FALSE,
download_path = "inst/images/backyard-spaceship-fill-example.jpeg"
)
original_mask <- image_read(system.file("/images/backyard-original_mask.jpeg", package = "bfl"))
original <- image_read(system.file("/images/backyard-original.jpeg", package = "bfl"))
output <- image_read(res$result$sample)
images_edited <- purrr::imap(
list(
"Original" = original,
"Original Mask" = original_mask,
"FLUX Fill Output" = output
),
~ image_annotate(
.x,
text = .y,
size = 100,
gravity = "south",
color = "white"
)
)
image_mosaic(image_append(do.call(c, images_edited)))
```
```{r, echo=FALSE}
knitr::include_graphics("inst/images/readme-flux-fill-pro-mosaic.jpeg")
```
#### FLUX Depth Pro
```{r, eval=FALSE}
control_image <- base64enc::base64encode(system.file("/images/low-res-pink-hair-figurine.jpeg", package = "bfl"))
res <- gen_flux_depth_pro1(
control_image = control_image,
prompt = paste0(
"small humanoid creature with pink hair gently grasped by a human thumb and three fingers, ",
"mars desert and sand dunes in the background, ultrarealistic, detailed"
),
seed = 2,
steps = 50,
prompt_upsampling = TRUE
)
original <- image_read(system.file("/images/low-res-pink-hair-figurine.jpeg", package = "bfl"))
output <- image_read(res$result$sample)
images_edited <- purrr::imap(
list(
"Original" = original,
"FLUX Depth Output" = output
),
~ image_annotate(
.x,
text = .y,
size = 100,
gravity = "south",
color = "white"
)
)
image_mosaic(image_append(do.call(c, images_edited)))
```
```{r, echo=FALSE}
knitr::include_graphics("inst/images/readme-flux-depth-pro-mosaic.jpeg")
```