Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,9 +62,9 @@ def run_multi_image_logic(prompt: str, images: List[str]) -> List[str]:
|
|
| 62 |
return output_images
|
| 63 |
|
| 64 |
# --- Gradio App UI ---
|
| 65 |
-
with gr.Blocks(theme=gr.themes.
|
| 66 |
-
gr.Markdown("# Nano Banana
|
| 67 |
-
gr.Markdown("
|
| 68 |
|
| 69 |
login_button = gr.LoginButton()
|
| 70 |
pro_message = gr.Markdown(visible=False)
|
|
@@ -96,7 +96,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 96 |
with gr.Column(scale=1):
|
| 97 |
output_gallery = gr.Gallery(label="Output")
|
| 98 |
selected_output_image_state = gr.State()
|
| 99 |
-
use_image_button = gr.Button("♻️ Use
|
| 100 |
|
| 101 |
# --- Event Handlers ---
|
| 102 |
|
|
@@ -105,7 +105,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 105 |
single_image: Optional[str],
|
| 106 |
multi_images: Optional[List[str]],
|
| 107 |
active_tab: str,
|
| 108 |
-
oauth_token: Optional[gr.OAuthToken] = None,
|
| 109 |
) -> List[str]:
|
| 110 |
if not verify_pro_status(oauth_token):
|
| 111 |
raise gr.Error("Access Denied. This service is for PRO users only.")
|
|
@@ -116,28 +116,22 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 116 |
|
| 117 |
single_tab.select(lambda: "single", None, active_tab_state)
|
| 118 |
multi_tab.select(lambda: "multiple", None, active_tab_state)
|
| 119 |
-
|
| 120 |
generate_button.click(
|
| 121 |
unified_generator,
|
| 122 |
-
|
|
|
|
| 123 |
outputs=[output_gallery],
|
| 124 |
)
|
| 125 |
|
| 126 |
-
#
|
| 127 |
def store_selected_image(evt: gr.SelectData):
|
| 128 |
-
|
| 129 |
-
return evt.value['image']
|
| 130 |
|
| 131 |
def reuse_output_image(selected_image_path):
|
| 132 |
-
"""
|
| 133 |
-
Takes the path from state and sends it to the single image input.
|
| 134 |
-
Also forces the UI to switch to the "Single Image" tab.
|
| 135 |
-
"""
|
| 136 |
if not selected_image_path:
|
| 137 |
gr.Warning("Please select an image from the output gallery first!")
|
| 138 |
return None, gr.update()
|
| 139 |
-
# Output 1: The image path for the gr.Image component
|
| 140 |
-
# Output 2: The ID of the tab to select for the gr.Tabs component
|
| 141 |
return selected_image_path, "single"
|
| 142 |
|
| 143 |
output_gallery.select(store_selected_image, None, selected_output_image_state)
|
|
@@ -163,7 +157,7 @@ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
|
|
| 163 |
"To unlock this and many other benefits, please consider upgrading your account.\n\n"
|
| 164 |
"### [**Become a PRO Member Today!**](https://huggingface.co/pro)"
|
| 165 |
)
|
| 166 |
-
return gr.update(visible=False), gr.update(visible=
|
| 167 |
|
| 168 |
demo.load(control_access, inputs=None, outputs=[main_interface, pro_message])
|
| 169 |
|
|
|
|
| 62 |
return output_images
|
| 63 |
|
| 64 |
# --- Gradio App UI ---
|
| 65 |
+
with gr.Blocks(theme=gr.themes.Citrus()) as demo:
|
| 66 |
+
gr.Markdown("# Nano Banana Image Generation")
|
| 67 |
+
gr.Markdown("Generate or edit images with FAL. **Sign in with Hugging Face to begin.**")
|
| 68 |
|
| 69 |
login_button = gr.LoginButton()
|
| 70 |
pro_message = gr.Markdown(visible=False)
|
|
|
|
| 96 |
with gr.Column(scale=1):
|
| 97 |
output_gallery = gr.Gallery(label="Output")
|
| 98 |
selected_output_image_state = gr.State()
|
| 99 |
+
use_image_button = gr.Button("♻️ Use Selected Image for Next Edit")
|
| 100 |
|
| 101 |
# --- Event Handlers ---
|
| 102 |
|
|
|
|
| 105 |
single_image: Optional[str],
|
| 106 |
multi_images: Optional[List[str]],
|
| 107 |
active_tab: str,
|
| 108 |
+
oauth_token: Optional[gr.OAuthToken] = None, # Gradio injects this automatically
|
| 109 |
) -> List[str]:
|
| 110 |
if not verify_pro_status(oauth_token):
|
| 111 |
raise gr.Error("Access Denied. This service is for PRO users only.")
|
|
|
|
| 116 |
|
| 117 |
single_tab.select(lambda: "single", None, active_tab_state)
|
| 118 |
multi_tab.select(lambda: "multiple", None, active_tab_state)
|
| 119 |
+
|
| 120 |
generate_button.click(
|
| 121 |
unified_generator,
|
| 122 |
+
# CORRECTED: login_button is removed. Gradio will inject the token via the type hint.
|
| 123 |
+
inputs=[prompt_input, image_input, gallery_input, active_tab_state],
|
| 124 |
outputs=[output_gallery],
|
| 125 |
)
|
| 126 |
|
| 127 |
+
# Handlers for the continuous editing loop
|
| 128 |
def store_selected_image(evt: gr.SelectData):
|
| 129 |
+
return evt.value['image']['path']
|
|
|
|
| 130 |
|
| 131 |
def reuse_output_image(selected_image_path):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
if not selected_image_path:
|
| 133 |
gr.Warning("Please select an image from the output gallery first!")
|
| 134 |
return None, gr.update()
|
|
|
|
|
|
|
| 135 |
return selected_image_path, "single"
|
| 136 |
|
| 137 |
output_gallery.select(store_selected_image, None, selected_output_image_state)
|
|
|
|
| 157 |
"To unlock this and many other benefits, please consider upgrading your account.\n\n"
|
| 158 |
"### [**Become a PRO Member Today!**](https://huggingface.co/pro)"
|
| 159 |
)
|
| 160 |
+
return gr.update(visible=False), gr.update(visible=true, value=message)
|
| 161 |
|
| 162 |
demo.load(control_access, inputs=None, outputs=[main_interface, pro_message])
|
| 163 |
|