fal 1.26.5__py3-none-any.whl → 1.27.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fal might be problematic. Click here for more details.
- fal/_fal_version.py +2 -2
- fal/toolkit/file/file.py +57 -44
- fal/toolkit/image/image.py +2 -2
- {fal-1.26.5.dist-info → fal-1.27.0.dist-info}/METADATA +1 -1
- {fal-1.26.5.dist-info → fal-1.27.0.dist-info}/RECORD +8 -8
- {fal-1.26.5.dist-info → fal-1.27.0.dist-info}/WHEEL +0 -0
- {fal-1.26.5.dist-info → fal-1.27.0.dist-info}/entry_points.txt +0 -0
- {fal-1.26.5.dist-info → fal-1.27.0.dist-info}/top_level.txt +0 -0
fal/_fal_version.py
CHANGED
fal/toolkit/file/file.py
CHANGED
|
@@ -61,7 +61,7 @@ def get_builtin_repository(id: RepositoryId | FileRepository) -> FileRepository:
|
|
|
61
61
|
get_builtin_repository.__module__ = "__main__"
|
|
62
62
|
|
|
63
63
|
DEFAULT_REPOSITORY: FileRepository | RepositoryId = "fal_v3"
|
|
64
|
-
FALLBACK_REPOSITORY: FileRepository | RepositoryId = "fal"
|
|
64
|
+
FALLBACK_REPOSITORY: list[FileRepository | RepositoryId] = ["cdn", "fal"]
|
|
65
65
|
OBJECT_LIFECYCLE_PREFERENCE_KEY = "x-fal-object-lifecycle-preference"
|
|
66
66
|
|
|
67
67
|
|
|
@@ -73,6 +73,42 @@ def FileField(*args, **kwargs):
|
|
|
73
73
|
return Field(*args, **kwargs)
|
|
74
74
|
|
|
75
75
|
|
|
76
|
+
def _try_with_fallback(
|
|
77
|
+
func: str,
|
|
78
|
+
args: list[Any],
|
|
79
|
+
repository: FileRepository | RepositoryId,
|
|
80
|
+
fallback_repository: Optional[
|
|
81
|
+
FileRepository | RepositoryId | list[FileRepository | RepositoryId]
|
|
82
|
+
],
|
|
83
|
+
save_kwargs: dict,
|
|
84
|
+
fallback_save_kwargs: dict,
|
|
85
|
+
) -> Any:
|
|
86
|
+
if fallback_repository is None:
|
|
87
|
+
fallback_repositories = []
|
|
88
|
+
elif isinstance(fallback_repository, list):
|
|
89
|
+
fallback_repositories = fallback_repository
|
|
90
|
+
else:
|
|
91
|
+
fallback_repositories = [fallback_repository]
|
|
92
|
+
|
|
93
|
+
attempts = [
|
|
94
|
+
(repository, save_kwargs),
|
|
95
|
+
*((fallback, fallback_save_kwargs) for fallback in fallback_repositories),
|
|
96
|
+
]
|
|
97
|
+
for idx, (repo, kwargs) in enumerate(attempts):
|
|
98
|
+
repo_obj = get_builtin_repository(repo)
|
|
99
|
+
try:
|
|
100
|
+
return getattr(repo_obj, func)(*args, **kwargs)
|
|
101
|
+
except Exception as exc:
|
|
102
|
+
if idx >= len(attempts) - 1:
|
|
103
|
+
raise
|
|
104
|
+
|
|
105
|
+
traceback.print_exc()
|
|
106
|
+
print(
|
|
107
|
+
f"Failed to {func} to repository {repo}: {exc}, "
|
|
108
|
+
f"falling back to {attempts[idx + 1][0]}"
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
|
|
76
112
|
class File(BaseModel):
|
|
77
113
|
# public properties
|
|
78
114
|
url: str = Field(
|
|
@@ -154,14 +190,12 @@ class File(BaseModel):
|
|
|
154
190
|
file_name: Optional[str] = None,
|
|
155
191
|
repository: FileRepository | RepositoryId = DEFAULT_REPOSITORY,
|
|
156
192
|
fallback_repository: Optional[
|
|
157
|
-
FileRepository | RepositoryId
|
|
193
|
+
FileRepository | RepositoryId | list[FileRepository | RepositoryId]
|
|
158
194
|
] = FALLBACK_REPOSITORY,
|
|
159
195
|
request: Optional[Request] = None,
|
|
160
196
|
save_kwargs: Optional[dict] = None,
|
|
161
197
|
fallback_save_kwargs: Optional[dict] = None,
|
|
162
198
|
) -> File:
|
|
163
|
-
repo = get_builtin_repository(repository)
|
|
164
|
-
|
|
165
199
|
save_kwargs = save_kwargs or {}
|
|
166
200
|
fallback_save_kwargs = fallback_save_kwargs or {}
|
|
167
201
|
|
|
@@ -177,21 +211,14 @@ class File(BaseModel):
|
|
|
177
211
|
"object_lifecycle_preference", object_lifecycle_preference
|
|
178
212
|
)
|
|
179
213
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
f"Failed to save bytes to repository {repository}: {exc}, "
|
|
189
|
-
f"falling back to {fallback_repository}"
|
|
190
|
-
)
|
|
191
|
-
|
|
192
|
-
fallback_repo = get_builtin_repository(fallback_repository)
|
|
193
|
-
|
|
194
|
-
url = fallback_repo.save(fdata, **fallback_save_kwargs)
|
|
214
|
+
url = _try_with_fallback(
|
|
215
|
+
"save",
|
|
216
|
+
[fdata],
|
|
217
|
+
repository=repository,
|
|
218
|
+
fallback_repository=fallback_repository,
|
|
219
|
+
save_kwargs=save_kwargs,
|
|
220
|
+
fallback_save_kwargs=fallback_save_kwargs,
|
|
221
|
+
)
|
|
195
222
|
|
|
196
223
|
return cls(
|
|
197
224
|
url=url,
|
|
@@ -209,7 +236,7 @@ class File(BaseModel):
|
|
|
209
236
|
repository: FileRepository | RepositoryId = DEFAULT_REPOSITORY,
|
|
210
237
|
multipart: bool | None = None,
|
|
211
238
|
fallback_repository: Optional[
|
|
212
|
-
FileRepository | RepositoryId
|
|
239
|
+
FileRepository | RepositoryId | list[FileRepository | RepositoryId]
|
|
213
240
|
] = FALLBACK_REPOSITORY,
|
|
214
241
|
request: Optional[Request] = None,
|
|
215
242
|
save_kwargs: Optional[dict] = None,
|
|
@@ -219,8 +246,6 @@ class File(BaseModel):
|
|
|
219
246
|
if not file_path.exists():
|
|
220
247
|
raise FileNotFoundError(f"File {file_path} does not exist")
|
|
221
248
|
|
|
222
|
-
repo = get_builtin_repository(repository)
|
|
223
|
-
|
|
224
249
|
save_kwargs = save_kwargs or {}
|
|
225
250
|
fallback_save_kwargs = fallback_save_kwargs or {}
|
|
226
251
|
|
|
@@ -238,29 +263,17 @@ class File(BaseModel):
|
|
|
238
263
|
save_kwargs.setdefault("multipart", multipart)
|
|
239
264
|
fallback_save_kwargs.setdefault("multipart", multipart)
|
|
240
265
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
file_path,
|
|
244
|
-
content_type=content_type,
|
|
245
|
-
**save_kwargs,
|
|
246
|
-
)
|
|
247
|
-
except Exception as exc:
|
|
248
|
-
if not fallback_repository:
|
|
249
|
-
raise
|
|
250
|
-
|
|
251
|
-
traceback.print_exc()
|
|
252
|
-
print(
|
|
253
|
-
f"Failed to save file to repository {repository}: {exc}, "
|
|
254
|
-
f"falling back to {fallback_repository}"
|
|
255
|
-
)
|
|
256
|
-
|
|
257
|
-
fallback_repo = get_builtin_repository(fallback_repository)
|
|
266
|
+
save_kwargs.setdefault("content_type", content_type)
|
|
267
|
+
fallback_save_kwargs.setdefault("content_type", content_type)
|
|
258
268
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
269
|
+
url, data = _try_with_fallback(
|
|
270
|
+
"save_file",
|
|
271
|
+
[file_path],
|
|
272
|
+
repository=repository,
|
|
273
|
+
fallback_repository=fallback_repository,
|
|
274
|
+
save_kwargs=save_kwargs,
|
|
275
|
+
fallback_save_kwargs=fallback_save_kwargs,
|
|
276
|
+
)
|
|
264
277
|
|
|
265
278
|
return cls(
|
|
266
279
|
url=url,
|
fal/toolkit/image/image.py
CHANGED
|
@@ -104,7 +104,7 @@ class Image(File):
|
|
|
104
104
|
file_name: str | None = None,
|
|
105
105
|
repository: FileRepository | RepositoryId = DEFAULT_REPOSITORY,
|
|
106
106
|
fallback_repository: Optional[
|
|
107
|
-
FileRepository | RepositoryId
|
|
107
|
+
FileRepository | RepositoryId | list[FileRepository | RepositoryId]
|
|
108
108
|
] = FALLBACK_REPOSITORY,
|
|
109
109
|
request: Optional[Request] = None,
|
|
110
110
|
) -> Image:
|
|
@@ -128,7 +128,7 @@ class Image(File):
|
|
|
128
128
|
file_name: str | None = None,
|
|
129
129
|
repository: FileRepository | RepositoryId = DEFAULT_REPOSITORY,
|
|
130
130
|
fallback_repository: Optional[
|
|
131
|
-
FileRepository | RepositoryId
|
|
131
|
+
FileRepository | RepositoryId | list[FileRepository | RepositoryId]
|
|
132
132
|
] = FALLBACK_REPOSITORY,
|
|
133
133
|
request: Optional[Request] = None,
|
|
134
134
|
) -> Image:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
fal/__init__.py,sha256=wXs1G0gSc7ZK60-bHe-B2m0l_sA6TrFk4BxY0tMoLe8,784
|
|
2
2
|
fal/__main__.py,sha256=4JMK66Wj4uLZTKbF-sT3LAxOsr6buig77PmOkJCRRxw,83
|
|
3
|
-
fal/_fal_version.py,sha256=
|
|
3
|
+
fal/_fal_version.py,sha256=HQ6H7oi4iB_J85euUvRmc0lAmH5ZJYlwVzjLXtFZBzM,513
|
|
4
4
|
fal/_serialization.py,sha256=npXNsFJ5G7jzBeBIyVMH01Ww34mGY4XWhHpRbSrTtnQ,7598
|
|
5
5
|
fal/_version.py,sha256=1BbTFnucNC_6ldKJ_ZoC722_UkW4S9aDBSW9L0fkKAw,2315
|
|
6
6
|
fal/api.py,sha256=wIEt21P1C7U-dYQEcyHUxxuuTnvzFyTpWDoHoaxq7tg,47385
|
|
@@ -59,14 +59,14 @@ fal/toolkit/types.py,sha256=kkbOsDKj1qPGb1UARTBp7yuJ5JUuyy7XQurYUBCdti8,4064
|
|
|
59
59
|
fal/toolkit/audio/__init__.py,sha256=sqNVfrKbppWlIGLoFTaaNTxLpVXsFHxOSHLA5VG547A,35
|
|
60
60
|
fal/toolkit/audio/audio.py,sha256=gt458h989iQ-EhQSH-mCuJuPBY4RneLJE05f_QWU1E0,572
|
|
61
61
|
fal/toolkit/file/__init__.py,sha256=FbNl6wD-P0aSSTUwzHt4HujBXrbC3ABmaigPQA4hRfg,70
|
|
62
|
-
fal/toolkit/file/file.py,sha256=
|
|
62
|
+
fal/toolkit/file/file.py,sha256=wDKK91i_1NJD5GGVSJPhFQ8C2FgxG2bJUnUexpHTjt8,10782
|
|
63
63
|
fal/toolkit/file/types.py,sha256=MMAH_AyLOhowQPesOv1V25wB4qgbJ3vYNlnTPbdSv1M,2304
|
|
64
64
|
fal/toolkit/file/providers/fal.py,sha256=Ph8v3Cm_eFu1b1AXiPKZQ5r8AWUALD3Wk18uw3z8RDQ,46910
|
|
65
65
|
fal/toolkit/file/providers/gcp.py,sha256=DKeZpm1MjwbvEsYvkdXUtuLIJDr_UNbqXj_Mfv3NTeo,2437
|
|
66
66
|
fal/toolkit/file/providers/r2.py,sha256=YqnYkkAo_ZKIa-xoSuDnnidUFwJWHdziAR34PE6irdI,3061
|
|
67
67
|
fal/toolkit/file/providers/s3.py,sha256=EI45T54Mox7lHZKROss_O8o0DIn3CHP9k1iaNYVrxvg,2714
|
|
68
68
|
fal/toolkit/image/__init__.py,sha256=m3OatPbBhcEOYyaTu_dgToxunUKoJu4bJVCWUoN7HX4,1838
|
|
69
|
-
fal/toolkit/image/image.py,sha256=
|
|
69
|
+
fal/toolkit/image/image.py,sha256=xmuIKU42DonGHnPS6V5MbLv-wBSlpVvfPTAy2A_Vds0,5614
|
|
70
70
|
fal/toolkit/image/safety_checker.py,sha256=S7ow-HuoVxC6ixHWWcBrAUm2dIlgq3sTAIull6xIbAg,3105
|
|
71
71
|
fal/toolkit/image/nsfw_filter/__init__.py,sha256=0d9D51EhcnJg8cZLYJjgvQJDZT74CfQu6mpvinRYRpA,216
|
|
72
72
|
fal/toolkit/image/nsfw_filter/env.py,sha256=iAP2Q3vzIl--DD8nr8o3o0goAwhExN2v0feYE0nIQjs,212
|
|
@@ -142,8 +142,8 @@ openapi_fal_rest/models/workflow_node_type.py,sha256=-FzyeY2bxcNmizKbJI8joG7byRi
|
|
|
142
142
|
openapi_fal_rest/models/workflow_schema.py,sha256=4K5gsv9u9pxx2ItkffoyHeNjBBYf6ur5bN4m_zePZNY,2019
|
|
143
143
|
openapi_fal_rest/models/workflow_schema_input.py,sha256=2OkOXWHTNsCXHWS6EGDFzcJKkW5FIap-2gfO233EvZQ,1191
|
|
144
144
|
openapi_fal_rest/models/workflow_schema_output.py,sha256=EblwSPAGfWfYVWw_WSSaBzQVju296is9o28rMBAd0mc,1196
|
|
145
|
-
fal-1.
|
|
146
|
-
fal-1.
|
|
147
|
-
fal-1.
|
|
148
|
-
fal-1.
|
|
149
|
-
fal-1.
|
|
145
|
+
fal-1.27.0.dist-info/METADATA,sha256=ORvnQCizWJSVgSPMATe-la0ZFLP35NisJx2-m-zNFgU,4089
|
|
146
|
+
fal-1.27.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
147
|
+
fal-1.27.0.dist-info/entry_points.txt,sha256=32zwTUC1U1E7nSTIGCoANQOQ3I7-qHG5wI6gsVz5pNU,37
|
|
148
|
+
fal-1.27.0.dist-info/top_level.txt,sha256=r257X1L57oJL8_lM0tRrfGuXFwm66i1huwQygbpLmHw,21
|
|
149
|
+
fal-1.27.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|