wuhp commited on
Commit
1dbd40f
·
verified ·
1 Parent(s): 851efc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -230,9 +230,9 @@ def greet():
230
 
231
  # Helper function to update send button interactivity based on prereqs
232
  # MODIFIED: Signature takes exactly 4 inputs, removed *args, **kwargs
233
- # MODIFIED: Return type hint changed to gr.Button.update
234
  # MODIFIED: Internal logic uses bool() check for simplicity
235
- def check_send_button_ready(hf_profile: gr.OAuthProfile | None, hf_token: gr.OAuthToken | None, gemini_key: str | None, gemini_model: str | None) -> gr.Button.update:
236
  """Checks if HF login and Gemini configuration are complete and returns update for button interactivity."""
237
  # --- START ENHANCED DEBUGGING LOGS ---
238
  print("\n--- check_send_button_ready START ---")
@@ -257,8 +257,8 @@ def check_send_button_ready(hf_profile: gr.OAuthProfile | None, hf_token: gr.OAu
257
  print(f"check_send_button_ready - HF Ready: {is_logged_in}, Gemini Ready: {is_gemini_ready}, Button Ready (boolean): {is_ready}")
258
  print("--- check_send_button_ready END ---\n")
259
 
260
- # Use gr.Button.update for clearer intent, although gr.update works
261
- return gr.Button.update(interactive=is_ready)
262
 
263
 
264
  # This is the main generator function for the workflow, triggered by the 'Send' button
@@ -271,7 +271,7 @@ def ai_workflow_chat(
271
  history: list[dict],
272
  hf_profile: gr.OAuthProfile | None,
273
  hf_token: gr.OAuthToken | None,
274
- # Input parameters corresponding to the State variables read by .click
275
  gemini_api_key_state: str | None,
276
  gemini_model_state: str | None,
277
  repo_id_state: str | None,
@@ -1044,7 +1044,7 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
1044
  # Call the update function and bind its output to the button component
1045
  check_send_button_ready,
1046
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1047
- outputs=[send_btn] # Update button interactivity using gr.Button.update return value
1048
  )
1049
 
1050
  # Handle Gemini Key Input change: Update key state -> Configure Gemini status -> Check prereqs and update button interactivity
@@ -1062,7 +1062,7 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
1062
  # Call the update function and bind its output to the button component
1063
  check_send_button_ready,
1064
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1065
- outputs=[send_btn] # Update button interactivity using gr.Button.update return value
1066
  )
1067
 
1068
  # Handle Gemini Model Selector change: Update model state -> Configure Gemini status -> Check prereqs and update button interactivity
@@ -1080,7 +1080,7 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
1080
  # Call the update function and bind its output to the button component
1081
  check_send_button_ready,
1082
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1083
- outputs=[send_btn] # Update button interactivity using gr.Button.update return value
1084
  )
1085
 
1086
  # Handle Grounding checkbox change: update grounding state
@@ -1155,7 +1155,7 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
1155
  # Since gemini_api_key_state state starts as "", button will initially be disabled.
1156
  check_send_button_ready,
1157
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1158
- outputs=[send_btn] # Update button interactivity using gr.Button.update return value
1159
  ).then(
1160
  # Action 4: Add the initial welcome message to the chatbot
1161
  greet,
 
230
 
231
  # Helper function to update send button interactivity based on prereqs
232
  # MODIFIED: Signature takes exactly 4 inputs, removed *args, **kwargs
233
+ # FIXED: Return type hint corrected to gr.update
234
  # MODIFIED: Internal logic uses bool() check for simplicity
235
+ def check_send_button_ready(hf_profile: gr.OAuthProfile | None, hf_token: gr.OAuthToken | None, gemini_key: str | None, gemini_model: str | None) -> gr.update:
236
  """Checks if HF login and Gemini configuration are complete and returns update for button interactivity."""
237
  # --- START ENHANCED DEBUGGING LOGS ---
238
  print("\n--- check_send_button_ready START ---")
 
257
  print(f"check_send_button_ready - HF Ready: {is_logged_in}, Gemini Ready: {is_gemini_ready}, Button Ready (boolean): {is_ready}")
258
  print("--- check_send_button_ready END ---\n")
259
 
260
+ # FIXED: Call gr.update instead of gr.Button.update
261
+ return gr.update(interactive=is_ready)
262
 
263
 
264
  # This is the main generator function for the workflow, triggered by the 'Send' button
 
271
  history: list[dict],
272
  hf_profile: gr.OAuthProfile | None,
273
  hf_token: gr.OAuthToken | None,
274
+ # Pass gemini_api_key and gemini_model as inputs - these come from the State variables
275
  gemini_api_key_state: str | None,
276
  gemini_model_state: str | None,
277
  repo_id_state: str | None,
 
1044
  # Call the update function and bind its output to the button component
1045
  check_send_button_ready,
1046
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1047
+ outputs=[send_btn] # Update button interactivity using gr.update return value
1048
  )
1049
 
1050
  # Handle Gemini Key Input change: Update key state -> Configure Gemini status -> Check prereqs and update button interactivity
 
1062
  # Call the update function and bind its output to the button component
1063
  check_send_button_ready,
1064
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1065
+ outputs=[send_btn] # Update button interactivity using gr.update return value
1066
  )
1067
 
1068
  # Handle Gemini Model Selector change: Update model state -> Configure Gemini status -> Check prereqs and update button interactivity
 
1080
  # Call the update function and bind its output to the button component
1081
  check_send_button_ready,
1082
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1083
+ outputs=[send_btn] # Update button interactivity using gr.update return value
1084
  )
1085
 
1086
  # Handle Grounding checkbox change: update grounding state
 
1155
  # Since gemini_api_key_state state starts as "", button will initially be disabled.
1156
  check_send_button_ready,
1157
  inputs=send_button_interactive_binding_inputs, # Use the explicit list with renamed states
1158
+ outputs=[send_btn] # Update button interactivity using gr.update return value
1159
  ).then(
1160
  # Action 4: Add the initial welcome message to the chatbot
1161
  greet,