Skip to content

Commit

Permalink
Remove * unpackng
Browse files Browse the repository at this point in the history
Change-Id: Iddc42b906dfab12dfa500f0f9774d58521684548
  • Loading branch information
MarkDaoust committed Sep 26, 2024
1 parent dfecd12 commit 02a1e38
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions google/generativeai/vision_models/_vision_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,19 @@ def to_mapping_value(value) -> struct_pb2.Struct:
# We got a dict (or something dict-like); convert it.
return struct_pb2.Struct(fields={k: to_value(v) for k, v in value.items()})

ASPECT_RATIOS = ["1:1", "9:16", "16:9", "4:3", "3:4"]
OUTPUT_MIME_TYPES = ["image/png", "image/jpeg"]
SAFETY_FILTER_LEVELS = ["block_most", "block_some", "block_few", "block_fewest"]
PERSON_GENERATIONS = ["dont_allow", "allow_adult", "allow_all"]

AspectRatio = Literal["1:1", "9:16", "16:9", "4:3", "3:4"]
ASPECT_RATIOS = AspectRatio.__args__

OutputMimeType = Literal["image/png", "image/jpeg"]
OUTPUT_MIME_TYPES = OutputMimeType.__args__

SafetyFilterLevel = Literal["block_most", "block_some", "block_few", "block_fewest"]
SAFETY_FILTER_LEVELS = SafetyFilterLevel.__args__

PersonGeneration = Literal["dont_allow", "allow_adult", "allow_all"]
PERSON_GENERATIONS = PersonGeneration.__args__


class Image:
"""Image."""
Expand Down Expand Up @@ -226,15 +235,13 @@ def _generate_images(
number_of_images: int = 1,
width: Optional[int] = None,
height: Optional[int] = None,
aspect_ratio: Optional[Literal[*ASPECT_RATIOS]] = None,
aspect_ratio: Optional[AspectRatio] = None,
guidance_scale: Optional[float] = None,
output_mime_type: Optional[Literal[*OUTPUT_MIME_TYPES]] = None,
output_mime_type: Optional[OutputMimeType] = None,
compression_quality: Optional[float] = None,
language: Optional[str] = None,
safety_filter_level: Optional[
Literal[*SAFETY_FILTER_LEVELS]
] = None,
person_generation: Optional[Literal[*PERSON_GENERATIONS]] = None,
safety_filter_level: Optional[SafetyFilterLevel] = None,
person_generation: Optional[PersonGeneration] = None,
) -> "ImageGenerationResponse":
"""Generates images from text prompt.
Expand Down Expand Up @@ -292,7 +299,7 @@ def _generate_images(
max_size = max(width or 0, height or 0) or None
if aspect_ratio is not None:
if aspect_ratio not in ASPECT_RATIOS:
raise ValueError(f'aspect_ratio not in {ASPECT_RATIOS}')
raise ValueError(f"aspect_ratio not in {ASPECT_RATIOS}")
parameters["aspectRatio"] = aspect_ratio
elif max_size:
# Note: The size needs to be a string
Expand All @@ -316,7 +323,7 @@ def _generate_images(
parameters["outputOptions"] = {}
if output_mime_type is not None:
if output_mime_type not in OUTPUT_MIME_TYPES:
raise ValueError(f'output_mime_type not in {OUTPUT_MIME_TYPES}')
raise ValueError(f"output_mime_type not in {OUTPUT_MIME_TYPES}")
parameters["outputOptions"]["mimeType"] = output_mime_type
shared_generation_parameters["mime_type"] = output_mime_type

Expand All @@ -326,7 +333,7 @@ def _generate_images(

if safety_filter_level is not None:
if safety_filter_level not in SAFETY_FILTER_LEVELS:
raise ValueError(f'safety_filter_level not in {SAFETY_FILTER_LEVELS}')
raise ValueError(f"safety_filter_level not in {SAFETY_FILTER_LEVELS}")
parameters["safetySetting"] = safety_filter_level
shared_generation_parameters["safety_filter_level"] = safety_filter_level

Expand Down Expand Up @@ -361,13 +368,13 @@ def generate_images(
*,
negative_prompt: Optional[str] = None,
number_of_images: int = 1,
aspect_ratio: Optional[Literal["1:1", "9:16", "16:9", "4:3", "3:4"]] = None,
aspect_ratio: Optional[AspectRatio] = None,
guidance_scale: Optional[float] = None,
language: Optional[str] = None,
safety_filter_level: Optional[
Literal["block_most", "block_some", "block_few", "block_fewest"]
SafetyFilterLevel
] = None,
person_generation: Optional[Literal["dont_allow", "allow_adult", "allow_all"]] = None,
person_generation: Optional[PersonGeneration] = None,
) -> "ImageGenerationResponse":
"""Generates images from text prompt.
Expand Down

0 comments on commit 02a1e38

Please sign in to comment.