Skip to content

Commit

Permalink
handle change to Civitai metadata schema for commercial usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Lincoln Stein committed Feb 28, 2024
1 parent 4418c11 commit fce2b15
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion invokeai/backend/model_manager/metadata/fetch/civitai.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _from_model_json(self, model_json: Dict[str, Any], version_id: Optional[int]
nsfw=model_json["nsfw"],
restrictions=LicenseRestrictions(
AllowNoCredit=model_json["allowNoCredit"],
AllowCommercialUse=CommercialUsage(model_json["allowCommercialUse"]),
AllowCommercialUse={CommercialUsage(x) for x in model_json["allowCommercialUse"]},
AllowDerivatives=model_json["allowDerivatives"],
AllowDifferentLicense=model_json["allowDifferentLicense"],
),
Expand Down
9 changes: 6 additions & 3 deletions invokeai/backend/model_manager/metadata/metadata_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class LicenseRestrictions(BaseModel):
AllowDifferentLicense: bool = Field(
description="if true, derivatives of this model be redistributed under a different license", default=False
)
AllowCommercialUse: Optional[CommercialUsage] = Field(
description="Type of commercial use allowed or 'No' if no commercial use is allowed.", default=None
AllowCommercialUse: Optional[Set[CommercialUsage] | CommercialUsage] = Field(
description="Type of commercial use allowed if no commercial use is allowed.", default=None
)


Expand Down Expand Up @@ -142,7 +142,10 @@ def allow_commercial_use(self) -> bool:
if self.restrictions.AllowCommercialUse is None:
return False
else:
return self.restrictions.AllowCommercialUse != CommercialUsage("None")
# accommodate schema change
acu = self.restrictions.AllowCommercialUse
commercial_usage = acu if isinstance(acu, set) else {acu}
return CommercialUsage.No not in commercial_usage

@property
def allow_derivatives(self) -> bool:
Expand Down
Loading

0 comments on commit fce2b15

Please sign in to comment.