wuhp commited on
Commit
b0ecca0
·
verified ·
1 Parent(s): d1b242d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -226,15 +226,15 @@ def add_bot_message(history: list[dict], bot_message: str) -> list[dict]:
226
  def greet():
227
  return [{"role": "assistant", "content": "Welcome! Please log in to Hugging Face and provide your Google AI Studio API key to start building Spaces. Once ready, type 'generate me a gradio app called myapp' or 'create' to begin."}]
228
 
229
- # Helper function to check if the send button should be interactive
230
- # Returns a boolean: True if ready, False otherwise
231
- def check_send_button_ready(profile: gr.OAuthProfile | None, token: gr.OAuthToken | None, api_key: str | None, model_name: str | None) -> bool:
232
- """Checks if HF login and Gemini configuration are complete."""
233
  is_logged_in = profile is not None and token is not None
234
  is_gemini_ready = api_key is not None and model_name is not None
235
  is_ready = is_logged_in and is_gemini_ready
236
  print(f"check_send_button_ready - HF Ready: {is_logged_in}, Gemini Ready: {is_gemini_ready}, Button Ready (boolean): {is_ready}")
237
- return is_ready
238
 
239
 
240
  # This is the main generator function for the workflow, triggered by the 'Send' button
@@ -945,10 +945,10 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
945
  inputs=[login_btn],
946
  outputs=[hf_profile, hf_token] # Update HF State variables
947
  ).then( # Chain the next action after state is updated
948
- # Call the boolean check function and bind its output to the button's interactive property
949
  check_send_button_ready,
950
  inputs=send_button_interactive_binding_inputs,
951
- outputs=[send_btn.interactive] # Update button interactivity directly
952
  )
953
 
954
  # Handle Gemini Key Input change: Update key state -> Configure Gemini status -> Check prereqs and update button interactivity
@@ -957,10 +957,10 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
957
  ).then(
958
  configure_gemini, inputs=[gemini_key, gemini_model], outputs=[gemini_status] # Update Gemini status
959
  ).then(
960
- # Call the boolean check function and bind its output to the button's interactive property
961
  check_send_button_ready,
962
  inputs=send_button_interactive_binding_inputs,
963
- outputs=[send_btn.interactive] # Update button interactivity directly
964
  )
965
 
966
  # Handle Gemini Model Selector change: Update model state -> Configure Gemini status -> Check prereqs and update button interactivity
@@ -969,10 +969,10 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
969
  ).then(
970
  configure_gemini, inputs=[gemini_key, gemini_model], outputs=[gemini_status] # Update Gemini status
971
  ).then(
972
- # Call the boolean check function and bind its output to the button's interactive property
973
  check_send_button_ready,
974
  inputs=send_button_interactive_binding_inputs,
975
- outputs=[send_btn.interactive] # Update button interactivity directly
976
  )
977
 
978
  # Handle Grounding checkbox change: update grounding state
@@ -1040,9 +1040,9 @@ with gr.Blocks(title="AI-Powered HF Space App Builder") as ai_builder_tab:
1040
  ).then(
1041
  # Action 3: Check prereqs and update send button interactivity based on initial states
1042
  # This uses the *initial* values of hf_profile, hf_token, gemini_key, and gemini_model states
1043
- check_send_button_ready, # Use the simpler boolean helper
1044
  inputs=send_button_interactive_binding_inputs,
1045
- outputs=[send_btn.interactive] # Update button interactivity directly
1046
  ).then(
1047
  # Action 4: Add the initial welcome message to the chatbot
1048
  greet,
 
226
  def greet():
227
  return [{"role": "assistant", "content": "Welcome! Please log in to Hugging Face and provide your Google AI Studio API key to start building Spaces. Once ready, type 'generate me a gradio app called myapp' or 'create' to begin."}]
228
 
229
+ # Helper function to update send button interactivity based on prereqs
230
+ # MODIFIED to return gr.update
231
+ def check_send_button_ready(profile: gr.OAuthProfile | None, token: gr.OAuthToken | None, api_key: str | None, model_name: str | None) -> gr.update:
232
+ """Checks if HF login and Gemini configuration are complete and returns update for button interactivity."""
233
  is_logged_in = profile is not None and token is not None
234
  is_gemini_ready = api_key is not None and model_name is not None
235
  is_ready = is_logged_in and is_gemini_ready
236
  print(f"check_send_button_ready - HF Ready: {is_logged_in}, Gemini Ready: {is_gemini_ready}, Button Ready (boolean): {is_ready}")
237
+ return gr.update(interactive=is_ready)
238
 
239
 
240
  # This is the main generator function for the workflow, triggered by the 'Send' button
 
945
  inputs=[login_btn],
946
  outputs=[hf_profile, hf_token] # Update HF State variables
947
  ).then( # Chain the next action after state is updated
948
+ # Call the update function and bind its output to the button component
949
  check_send_button_ready,
950
  inputs=send_button_interactive_binding_inputs,
951
+ outputs=[send_btn] # Update button interactivity using gr.update return value
952
  )
953
 
954
  # Handle Gemini Key Input change: Update key state -> Configure Gemini status -> Check prereqs and update button interactivity
 
957
  ).then(
958
  configure_gemini, inputs=[gemini_key, gemini_model], outputs=[gemini_status] # Update Gemini status
959
  ).then(
960
+ # Call the update function and bind its output to the button component
961
  check_send_button_ready,
962
  inputs=send_button_interactive_binding_inputs,
963
+ outputs=[send_btn] # Update button interactivity using gr.update return value
964
  )
965
 
966
  # Handle Gemini Model Selector change: Update model state -> Configure Gemini status -> Check prereqs and update button interactivity
 
969
  ).then(
970
  configure_gemini, inputs=[gemini_key, gemini_model], outputs=[gemini_status] # Update Gemini status
971
  ).then(
972
+ # Call the update function and bind its output to the button component
973
  check_send_button_ready,
974
  inputs=send_button_interactive_binding_inputs,
975
+ outputs=[send_btn] # Update button interactivity using gr.update return value
976
  )
977
 
978
  # Handle Grounding checkbox change: update grounding state
 
1040
  ).then(
1041
  # Action 3: Check prereqs and update send button interactivity based on initial states
1042
  # This uses the *initial* values of hf_profile, hf_token, gemini_key, and gemini_model states
1043
+ check_send_button_ready, # Use the updated helper function
1044
  inputs=send_button_interactive_binding_inputs,
1045
+ outputs=[send_btn] # Update button interactivity using gr.update return value
1046
  ).then(
1047
  # Action 4: Add the initial welcome message to the chatbot
1048
  greet,