Spaces:
Running
Running
pro (#14)
Browse files- Upload 2 files (d34b13a3b1699de16bd363bcfc6fc1ceacbe4061)
- Update app.py (a8c4dd66c0b66edd509f01a66c7fd2cd32ed6a39)
- app.py +37 -11
- nano_banana_pros.png +2 -2
- nano_banana_pros_light.png +2 -2
app.py
CHANGED
|
@@ -138,6 +138,7 @@ if not GOOGLE_API_KEY:
|
|
| 138 |
raise ValueError("GOOGLE_API_KEY environment variable not set.")
|
| 139 |
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
|
| 140 |
GEMINI_MODEL_NAME = 'gemini-2.5-flash-image'
|
|
|
|
| 141 |
|
| 142 |
def verify_pro_status(token: Optional[Union[gr.OAuthToken, str]]) -> bool:
|
| 143 |
"""Verifies if the user is a Hugging Face PRO user or part of an enterprise org."""
|
|
@@ -261,7 +262,7 @@ def _generate_video_segment(input_image_path: str, output_image_path: str, promp
|
|
| 261 |
)
|
| 262 |
return result[0]["video"]
|
| 263 |
|
| 264 |
-
def unified_image_generator(prompt: str, images: Optional[List[str]], previous_video_path: Optional[str], last_frame_path: Optional[str], aspect_ratio: str, manual_token: str, oauth_token: Optional[gr.OAuthToken]) -> tuple:
|
| 265 |
if not (verify_pro_status(oauth_token) or verify_pro_status(manual_token)):
|
| 266 |
raise gr.Error("Access Denied.")
|
| 267 |
|
|
@@ -277,21 +278,35 @@ def unified_image_generator(prompt: str, images: Optional[List[str]], previous_v
|
|
| 277 |
contents = [Image.open(image_path[0]) for image_path in images] if images else []
|
| 278 |
contents.append(prompt)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
| 280 |
# Create config with aspect ratio (omit image_config if Auto is selected)
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
)
|
| 285 |
-
else:
|
| 286 |
generate_content_config = types.GenerateContentConfig(
|
| 287 |
response_modalities=["IMAGE", "TEXT"],
|
| 288 |
image_config=types.ImageConfig(
|
| 289 |
-
|
| 290 |
),
|
| 291 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
response = client.models.generate_content(
|
| 294 |
-
model=
|
| 295 |
contents=contents,
|
| 296 |
config=generate_content_config
|
| 297 |
)
|
|
@@ -356,7 +371,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
|
|
| 356 |
<img class="logo-dark" src='https://huggingface.co/spaces/multimodalart/nano-banana/resolve/main/nano_banana_pros.png' style='margin: 0 auto; max-width: 650px' />
|
| 357 |
<img class="logo-light" src='https://huggingface.co/spaces/multimodalart/nano-banana/resolve/main/nano_banana_pros_light.png' style='margin: 0 auto; max-width: 650px' />
|
| 358 |
''')
|
| 359 |
-
gr.HTML("<h3 style='text-align:center'>Hugging Face PRO users can use Google's Nano Banana
|
| 360 |
pro_message = gr.Markdown(visible=False)
|
| 361 |
main_interface = gr.Column(visible=False)
|
| 362 |
|
|
@@ -368,12 +383,23 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
|
|
| 368 |
with gr.Column(scale=1):
|
| 369 |
image_input_gallery = gr.Gallery(label="Upload one or more images here. Leave empty for text-to-image", file_types=["image"], height="auto")
|
| 370 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Turns this photo into a masterpiece")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
aspect_ratio_dropdown = gr.Dropdown(
|
| 372 |
-
label="Aspect Ratio",
|
| 373 |
choices=["Auto", "1:1", "9:16", "16:9", "3:4", "4:3", "3:2", "2:3", "5:4", "4:5", "21:9"],
|
| 374 |
value="Auto",
|
| 375 |
interactive=True
|
| 376 |
)
|
|
|
|
|
|
|
|
|
|
| 377 |
generate_button = gr.Button("Generate", variant="primary")
|
| 378 |
with gr.Column(scale=1):
|
| 379 |
output_image = gr.Image(label="Output", interactive=False, elem_id="output", type="filepath")
|
|
@@ -392,7 +418,7 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=css) as demo:
|
|
| 392 |
gr.on(
|
| 393 |
triggers=[generate_button.click, prompt_input.submit],
|
| 394 |
fn=unified_image_generator,
|
| 395 |
-
inputs=[prompt_input, image_input_gallery, previous_video_state, last_frame_of_video_state, aspect_ratio_dropdown, manual_token],
|
| 396 |
outputs=[output_image, create_video_button, extend_video_button, video_group],
|
| 397 |
api_name=False
|
| 398 |
)
|
|
|
|
| 138 |
raise ValueError("GOOGLE_API_KEY environment variable not set.")
|
| 139 |
client = genai.Client(api_key=os.environ.get("GOOGLE_API_KEY"))
|
| 140 |
GEMINI_MODEL_NAME = 'gemini-2.5-flash-image'
|
| 141 |
+
GEMINI_PRO_MODEL_NAME = 'gemini-3-pro-image-preview'
|
| 142 |
|
| 143 |
def verify_pro_status(token: Optional[Union[gr.OAuthToken, str]]) -> bool:
|
| 144 |
"""Verifies if the user is a Hugging Face PRO user or part of an enterprise org."""
|
|
|
|
| 262 |
)
|
| 263 |
return result[0]["video"]
|
| 264 |
|
| 265 |
+
def unified_image_generator(prompt: str, images: Optional[List[str]], previous_video_path: Optional[str], last_frame_path: Optional[str], aspect_ratio: str, use_pro_model: bool, manual_token: str, oauth_token: Optional[gr.OAuthToken]) -> tuple:
|
| 266 |
if not (verify_pro_status(oauth_token) or verify_pro_status(manual_token)):
|
| 267 |
raise gr.Error("Access Denied.")
|
| 268 |
|
|
|
|
| 278 |
contents = [Image.open(image_path[0]) for image_path in images] if images else []
|
| 279 |
contents.append(prompt)
|
| 280 |
|
| 281 |
+
# Select model based on checkbox
|
| 282 |
+
model_name = GEMINI_PRO_MODEL_NAME if use_pro_model else GEMINI_MODEL_NAME
|
| 283 |
+
|
| 284 |
# Create config with aspect ratio (omit image_config if Auto is selected)
|
| 285 |
+
# Note: PRO model uses image_size instead of aspect_ratio
|
| 286 |
+
if use_pro_model:
|
| 287 |
+
# Gemini 3 Pro uses image_size parameter
|
|
|
|
|
|
|
| 288 |
generate_content_config = types.GenerateContentConfig(
|
| 289 |
response_modalities=["IMAGE", "TEXT"],
|
| 290 |
image_config=types.ImageConfig(
|
| 291 |
+
image_size="1K", # Options: "1K", "2K", "4K"
|
| 292 |
),
|
| 293 |
)
|
| 294 |
+
else:
|
| 295 |
+
# Gemini 2.5 Flash uses aspect_ratio parameter
|
| 296 |
+
if aspect_ratio == "Auto":
|
| 297 |
+
generate_content_config = types.GenerateContentConfig(
|
| 298 |
+
response_modalities=["IMAGE", "TEXT"],
|
| 299 |
+
)
|
| 300 |
+
else:
|
| 301 |
+
generate_content_config = types.GenerateContentConfig(
|
| 302 |
+
response_modalities=["IMAGE", "TEXT"],
|
| 303 |
+
image_config=types.ImageConfig(
|
| 304 |
+
aspect_ratio=aspect_ratio,
|
| 305 |
+
),
|
| 306 |
+
)
|
| 307 |
|
| 308 |
response = client.models.generate_content(
|
| 309 |
+
model=model_name,
|
| 310 |
contents=contents,
|
| 311 |
config=generate_content_config
|
| 312 |
)
|
|
|
|
| 371 |
<img class="logo-dark" src='https://huggingface.co/spaces/multimodalart/nano-banana/resolve/main/nano_banana_pros.png' style='margin: 0 auto; max-width: 650px' />
|
| 372 |
<img class="logo-light" src='https://huggingface.co/spaces/multimodalart/nano-banana/resolve/main/nano_banana_pros_light.png' style='margin: 0 auto; max-width: 650px' />
|
| 373 |
''')
|
| 374 |
+
gr.HTML("<h3 style='text-align:center'>Hugging Face PRO users can use Google's Nano Banana and Nano Banana PRO on this Space. <a href='http://huggingface.co/subscribe/pro?source=nana_banana' target='_blank'>Subscribe to PRO</a></h3>", elem_id="sub_title")
|
| 375 |
pro_message = gr.Markdown(visible=False)
|
| 376 |
main_interface = gr.Column(visible=False)
|
| 377 |
|
|
|
|
| 383 |
with gr.Column(scale=1):
|
| 384 |
image_input_gallery = gr.Gallery(label="Upload one or more images here. Leave empty for text-to-image", file_types=["image"], height="auto")
|
| 385 |
prompt_input = gr.Textbox(label="Prompt", placeholder="Turns this photo into a masterpiece")
|
| 386 |
+
|
| 387 |
+
# Model selection checkbox
|
| 388 |
+
use_pro_checkbox = gr.Checkbox(
|
| 389 |
+
label="🌟 Use Nano Banana PRO (Gemini 3 Pro Image) - Higher quality, slower generation",
|
| 390 |
+
value=False,
|
| 391 |
+
interactive=True
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
aspect_ratio_dropdown = gr.Dropdown(
|
| 395 |
+
label="Aspect Ratio (only for standard model)",
|
| 396 |
choices=["Auto", "1:1", "9:16", "16:9", "3:4", "4:3", "3:2", "2:3", "5:4", "4:5", "21:9"],
|
| 397 |
value="Auto",
|
| 398 |
interactive=True
|
| 399 |
)
|
| 400 |
+
|
| 401 |
+
gr.Markdown("💡 **Tip:** PRO model uses fixed 1K resolution. Aspect ratio setting is ignored when PRO is enabled.")
|
| 402 |
+
|
| 403 |
generate_button = gr.Button("Generate", variant="primary")
|
| 404 |
with gr.Column(scale=1):
|
| 405 |
output_image = gr.Image(label="Output", interactive=False, elem_id="output", type="filepath")
|
|
|
|
| 418 |
gr.on(
|
| 419 |
triggers=[generate_button.click, prompt_input.submit],
|
| 420 |
fn=unified_image_generator,
|
| 421 |
+
inputs=[prompt_input, image_input_gallery, previous_video_state, last_frame_of_video_state, aspect_ratio_dropdown, use_pro_checkbox, manual_token],
|
| 422 |
outputs=[output_image, create_video_button, extend_video_button, video_group],
|
| 423 |
api_name=False
|
| 424 |
)
|
nano_banana_pros.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|
nano_banana_pros_light.png
CHANGED
|
Git LFS Details
|
|
Git LFS Details
|