Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
柴进
/
GoogleNanoBananaApp
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
5563b76b
authored
2026-01-13 16:41:44 +0800
by
柴进
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
增加软件的降级模式,在慢速模式的用量用光后可以回退到极速模式
1 parent
683c07f9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
151 additions
and
13 deletions
config.json
image_generator.py
config.json
View file @
5563b76
{
"api_key"
:
"AIzaSy
BRIH8iItqTZXg7d4zAWVNhyit2CZbXWIU
"
,
"api_key"
:
"AIzaSy
DKfEF-yHbKxGirdHgaGa7jNSzxyWfReus
"
,
"saved_prompts"
:
[
"主石换成闪耀的祖母绿"
,
"主石换成闪耀的钻石"
,
...
...
image_generator.py
View file @
5563b76
...
...
@@ -1470,6 +1470,17 @@ class ImageGeneratorWindow(QMainWindow):
settings_group
=
QGroupBox
(
"生成设置"
)
settings_layout
=
QVBoxLayout
()
# 生成模式(放在最前面)
settings_layout
.
addWidget
(
QLabel
(
"生成模式"
))
self
.
generation_mode
=
QComboBox
()
self
.
generation_mode
.
addItems
([
"极速模式"
,
"慢速模式"
])
self
.
generation_mode
.
setCurrentIndex
(
0
)
# Default to 极速模式
self
.
generation_mode
.
currentIndexChanged
.
connect
(
self
.
on_generation_mode_changed
)
settings_layout
.
addWidget
(
self
.
generation_mode
)
settings_layout
.
addSpacing
(
10
)
# 宽高比
settings_layout
.
addWidget
(
QLabel
(
"宽高比"
))
self
.
aspect_ratio
=
QComboBox
()
self
.
aspect_ratio
.
addItems
([
"1:1"
,
"2:3"
,
"3:2"
,
"3:4"
,
"4:3"
,
"4:5"
,
"5:4"
,
"9:16"
,
"16:9"
,
"21:9"
])
...
...
@@ -1477,10 +1488,12 @@ class ImageGeneratorWindow(QMainWindow):
settings_layout
.
addSpacing
(
10
)
# 图片尺寸
settings_layout
.
addWidget
(
QLabel
(
"图片尺寸"
))
self
.
image_size
=
QComboBox
()
self
.
image_size
.
addItems
([
"1K"
,
"2K"
,
"4K"
])
self
.
image_size
.
setCurrentIndex
(
1
)
# Default to 2K
self
.
image_size
.
setCurrentIndex
(
0
)
# Default to 1K for 极速模式
self
.
image_size
.
currentIndexChanged
.
connect
(
self
.
on_image_size_changed
)
settings_layout
.
addWidget
(
self
.
image_size
)
settings_layout
.
addSpacing
(
10
)
...
...
@@ -1764,6 +1777,9 @@ class ImageGeneratorWindow(QMainWindow):
self
.
status_label
.
setText
(
f
"● 已添加 {valid_count} 张参考图片"
)
self
.
status_label
.
setStyleSheet
(
"QLabel { color: #34C759; }"
)
self
.
logger
.
info
(
f
"图片上传完成,有效图片: {valid_count} 张"
)
# 检查极速模式下的多图限制
self
.
check_multi_image_mode_conflict
()
else
:
self
.
logger
.
info
(
"用户取消了图片选择"
)
...
...
@@ -1793,6 +1809,9 @@ class ImageGeneratorWindow(QMainWindow):
self
.
image_count_label
.
setText
(
f
"已选择 {len(self.uploaded_images)} 张"
)
self
.
status_label
.
setText
(
f
"● 已通过拖拽添加 {added_count} 张参考图片"
)
self
.
status_label
.
setStyleSheet
(
"QLabel { color: #34C759; }"
)
# 检查极速模式下的多图限制
self
.
check_multi_image_mode_conflict
()
else
:
self
.
logger
.
warning
(
"没有找到有效的拖拽图片文件"
)
QMessageBox
.
warning
(
self
,
"警告"
,
"没有找到有效的图片文件"
)
...
...
@@ -1835,6 +1854,9 @@ class ImageGeneratorWindow(QMainWindow):
self
.
status_label
.
setText
(
"● 已添加剪贴板图片"
)
self
.
status_label
.
setStyleSheet
(
"QLabel { color: #34C759; }"
)
self
.
logger
.
info
(
f
"剪贴板图片已成功保存到: {temp_file_path}"
)
# 检查极速模式下的多图限制
self
.
check_multi_image_mode_conflict
()
else
:
self
.
logger
.
error
(
"图片保存失败"
)
QMessageBox
.
critical
(
self
,
"错误"
,
"无法保存剪贴板图片"
)
...
...
@@ -2088,6 +2110,63 @@ class ImageGeneratorWindow(QMainWindow):
self
.
status_label
.
setText
(
"● 已删除提示词"
)
self
.
status_label
.
setStyleSheet
(
"QLabel { color: #34C759; }"
)
def
get_selected_model
(
self
):
"""根据生成模式返回对应的模型名称"""
if
self
.
generation_mode
.
currentText
()
==
"慢速模式"
:
return
"gemini-3-pro-image-preview"
else
:
return
"gemini-2.5-flash-image-preview"
def
on_generation_mode_changed
(
self
,
index
):
"""生成模式切换时的处理"""
if
self
.
generation_mode
.
currentText
()
==
"极速模式"
:
# 极速模式强制使用1K
self
.
image_size
.
setCurrentIndex
(
0
)
# 1K
def
on_image_size_changed
(
self
,
index
):
"""图片尺寸切换时的处理"""
selected_size
=
self
.
image_size
.
currentText
()
current_mode
=
self
.
generation_mode
.
currentText
()
# 如果选择2K或4K,且当前是极速模式,提示切换
if
selected_size
in
[
"2K"
,
"4K"
]
and
current_mode
==
"极速模式"
:
reply
=
QMessageBox
.
question
(
self
,
"模式切换确认"
,
f
"{selected_size} 只有慢速模式支持,是否确认切换到慢速模式?"
,
QMessageBox
.
Yes
|
QMessageBox
.
No
,
QMessageBox
.
No
)
if
reply
==
QMessageBox
.
Yes
:
self
.
generation_mode
.
setCurrentIndex
(
1
)
# 切换到慢速模式
else
:
# 用户拒绝,恢复到1K
self
.
image_size
.
setCurrentIndex
(
0
)
def
check_multi_image_mode_conflict
(
self
):
"""检查极速模式下的多图限制"""
current_mode
=
self
.
generation_mode
.
currentText
()
image_count
=
len
(
self
.
uploaded_images
)
# 如果是极速模式且有多张图片,提示切换
if
current_mode
==
"极速模式"
and
image_count
>
1
:
reply
=
QMessageBox
.
question
(
self
,
"模式切换确认"
,
f
"极速模式只支持单张参考图,您已上传 {image_count} 张图片。
\n
是否切换到慢速模式以使用多图功能?"
,
QMessageBox
.
Yes
|
QMessageBox
.
No
,
QMessageBox
.
No
)
if
reply
==
QMessageBox
.
Yes
:
self
.
generation_mode
.
setCurrentIndex
(
1
)
# 切换到慢速模式
else
:
# 用户拒绝,移除多余的图片,只保留第一张
self
.
uploaded_images
=
self
.
uploaded_images
[:
1
]
self
.
update_image_preview
()
self
.
image_count_label
.
setText
(
f
"已选择 {len(self.uploaded_images)} 张"
)
self
.
status_label
.
setText
(
"● 已保留第一张参考图片"
)
self
.
status_label
.
setStyleSheet
(
"QLabel { color: #FF9500; }"
)
def
generate_image_async
(
self
):
"""Submit image generation task to queue"""
from
task_queue
import
TaskType
...
...
@@ -2108,7 +2187,7 @@ class ImageGeneratorWindow(QMainWindow):
reference_images
=
self
.
uploaded_images
.
copy
(),
aspect_ratio
=
self
.
aspect_ratio
.
currentText
(),
image_size
=
self
.
image_size
.
currentText
(),
model
=
"gemini-3-pro-image-preview"
,
model
=
self
.
get_selected_model
()
,
user_name
=
self
.
authenticated_user
,
device_name
=
socket
.
gethostname
()
)
...
...
@@ -2702,17 +2781,28 @@ class ImageGenerationWorker(QThread):
self
.
progress
.
emit
(
"正在生成图片..."
)
# Generation config
config
=
types
.
GenerateContentConfig
(
response_modalities
=
[
"IMAGE"
],
image_config
=
types
.
ImageConfig
(
aspect_ratio
=
self
.
aspect_ratio
,
image_size
=
self
.
image_size
# Note: gemini-2.5-flash-image-preview does not support image_size parameter
if
"gemini-3-pro-image-preview"
in
self
.
model
:
# Gemini 3 Pro supports both aspect_ratio and image_size
config
=
types
.
GenerateContentConfig
(
response_modalities
=
[
"IMAGE"
],
image_config
=
types
.
ImageConfig
(
aspect_ratio
=
self
.
aspect_ratio
,
image_size
=
self
.
image_size
)
)
else
:
# Gemini 2.5 Flash only supports aspect_ratio (fixed 1024px output)
config
=
types
.
GenerateContentConfig
(
response_modalities
=
[
"IMAGE"
],
image_config
=
types
.
ImageConfig
(
aspect_ratio
=
self
.
aspect_ratio
)
)
)
# Generate
response
=
client
.
models
.
generate_content
(
model
=
"gemini-3-pro-image-preview"
,
model
=
self
.
model
,
contents
=
content_parts
,
config
=
config
)
...
...
@@ -3211,6 +3301,19 @@ class StyleDesignerTab(QWidget):
settings_group
=
QGroupBox
(
"生成设置"
)
settings_layout
=
QVBoxLayout
()
# 生成模式(放在最前面)
mode_label
=
QLabel
(
"生成模式"
)
mode_label
.
setStyleSheet
(
"QLabel { font-size: 14px; line-height: 18px; }"
)
settings_layout
.
addWidget
(
mode_label
)
self
.
generation_mode
=
QComboBox
()
self
.
generation_mode
.
addItems
([
"极速模式"
,
"慢速模式"
])
self
.
generation_mode
.
setCurrentIndex
(
0
)
# Default to 极速模式
self
.
generation_mode
.
currentIndexChanged
.
connect
(
self
.
on_generation_mode_changed
)
settings_layout
.
addWidget
(
self
.
generation_mode
)
settings_layout
.
addSpacing
(
10
)
# 宽高比
aspect_label
=
QLabel
(
"宽高比"
)
aspect_label
.
setStyleSheet
(
"QLabel { font-size: 14px; line-height: 18px; }"
)
settings_layout
.
addWidget
(
aspect_label
)
...
...
@@ -3220,12 +3323,14 @@ class StyleDesignerTab(QWidget):
settings_layout
.
addSpacing
(
10
)
# 图片尺寸
size_label
=
QLabel
(
"图片尺寸"
)
size_label
.
setStyleSheet
(
"QLabel { font-size: 14px; line-height: 18px; }"
)
settings_layout
.
addWidget
(
size_label
)
self
.
image_size
=
QComboBox
()
self
.
image_size
.
addItems
([
"1K"
,
"2K"
,
"4K"
])
self
.
image_size
.
setCurrentIndex
(
1
)
self
.
image_size
.
setCurrentIndex
(
0
)
# Default to 1K for 极速模式
self
.
image_size
.
currentIndexChanged
.
connect
(
self
.
on_image_size_changed
)
settings_layout
.
addWidget
(
self
.
image_size
)
settings_layout
.
addSpacing
(
10
)
...
...
@@ -3503,6 +3608,39 @@ class StyleDesignerTab(QWidget):
button
.
setText
(
"🔒"
)
button
.
setToolTip
(
"字段已锁定"
)
def
get_selected_model
(
self
):
"""根据生成模式返回对应的模型名称"""
if
self
.
generation_mode
.
currentText
()
==
"慢速模式"
:
return
"gemini-3-pro-image-preview"
else
:
return
"gemini-2.5-flash-image-preview"
def
on_generation_mode_changed
(
self
,
index
):
"""生成模式切换时的处理"""
if
self
.
generation_mode
.
currentText
()
==
"极速模式"
:
# 极速模式强制使用1K
self
.
image_size
.
setCurrentIndex
(
0
)
# 1K
def
on_image_size_changed
(
self
,
index
):
"""图片尺寸切换时的处理"""
selected_size
=
self
.
image_size
.
currentText
()
current_mode
=
self
.
generation_mode
.
currentText
()
# 如果选择2K或4K,且当前是极速模式,提示切换
if
selected_size
in
[
"2K"
,
"4K"
]
and
current_mode
==
"极速模式"
:
reply
=
QMessageBox
.
question
(
self
,
"模式切换确认"
,
f
"{selected_size} 只有慢速模式支持,是否确认切换到慢速模式?"
,
QMessageBox
.
Yes
|
QMessageBox
.
No
,
QMessageBox
.
No
)
if
reply
==
QMessageBox
.
Yes
:
self
.
generation_mode
.
setCurrentIndex
(
1
)
# 切换到慢速模式
else
:
# 用户拒绝,恢复到1K
self
.
image_size
.
setCurrentIndex
(
0
)
def
generate_image
(
self
):
"""Submit image generation task to queue"""
from
task_queue
import
TaskType
...
...
@@ -3516,7 +3654,7 @@ class StyleDesignerTab(QWidget):
# 获取设置
aspect_ratio
=
self
.
aspect_ratio
.
currentText
()
image_size
=
self
.
image_size
.
currentText
()
model
=
"gemini-3-pro-image-preview"
model
=
self
.
get_selected_model
()
# 获取父窗口的 API key
if
not
hasattr
(
self
.
parent_window
,
'api_key'
)
or
not
self
.
parent_window
.
api_key
:
...
...
@@ -3620,7 +3758,7 @@ class StyleDesignerTab(QWidget):
reference_images
=
[],
# 款式设计无参考图
aspect_ratio
=
self
.
aspect_ratio
.
currentText
(),
image_size
=
self
.
image_size
.
currentText
(),
model
=
"gemini-3-pro-image-preview"
model
=
self
.
get_selected_model
()
)
self
.
logger
.
info
(
f
"款式设计已添加到历史记录: {timestamp}"
)
...
...
Please
register
or
sign in
to post a comment