Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -140,10 +140,8 @@ def get_container_logs_action(repo_id, profile, token):
|
|
140 |
def configure_gemini(api_key: str | None, model_name: str | None) -> str:
|
141 |
"""Configures the Gemini API and checks if the model is accessible."""
|
142 |
if not api_key:
|
143 |
-
# Keep the message about key not set
|
144 |
return "⚠️ Gemini API key is not set."
|
145 |
if not model_name:
|
146 |
-
# Keep the message about model not selected
|
147 |
return "⚠️ Please select a Gemini model."
|
148 |
try:
|
149 |
genai.configure(api_key=api_key)
|
@@ -231,10 +229,27 @@ def greet():
|
|
231 |
# FIX: Added *args, **kwargs to accept any extra arguments passed by Gradio chaining
|
232 |
def check_send_button_ready(profile: gr.OAuthProfile | None, token: gr.OAuthToken | None, api_key: str | None, model_name: str | None, *args, **kwargs) -> gr.update:
|
233 |
"""Checks if HF login and Gemini configuration are complete and returns update for button interactivity."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
is_logged_in = profile is not None and token is not None
|
235 |
is_gemini_ready = api_key is not None and model_name is not None
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
is_ready = is_logged_in and is_gemini_ready
|
237 |
print(f"check_send_button_ready - HF Ready: {is_logged_in}, Gemini Ready: {is_gemini_ready}, Button Ready (boolean): {is_ready}")
|
|
|
|
|
238 |
return gr.update(interactive=is_ready)
|
239 |
|
240 |
|
@@ -314,19 +329,22 @@ def ai_workflow_chat(
|
|
314 |
if state == STATE_IDLE:
|
315 |
# Check workflow prerequisites before starting any workflow actions
|
316 |
# The Send button should already be disabled if these aren't met, but double-check
|
|
|
|
|
317 |
if not (hf_profile and hf_token):
|
|
|
318 |
history = add_bot_message(history, "Workflow paused: Please log in to Hugging Face first.")
|
319 |
yield (history, repo_id, state, updated_preview, updated_run, updated_build,
|
320 |
attempts, app_desc, repo_name, generated_code, use_grounding)
|
321 |
-
return
|
322 |
|
323 |
if not (gemini_api_key and gemini_model):
|
324 |
-
#
|
325 |
-
# but we still need the key/model for the workflow itself.
|
326 |
history = add_bot_message(history, "Workflow cannot start: Please ensure your Gemini API key is entered and a model is selected.")
|
327 |
yield (history, repo_id, state, updated_preview, updated_run, updated_build,
|
328 |
attempts, app_desc, repo_name, generated_code, use_grounding)
|
329 |
-
return
|
|
|
330 |
|
331 |
# Look for specific commands in the user's message
|
332 |
reset_match = "reset" in message.lower()
|
|
|
140 |
def configure_gemini(api_key: str | None, model_name: str | None) -> str:
|
141 |
"""Configures the Gemini API and checks if the model is accessible."""
|
142 |
if not api_key:
|
|
|
143 |
return "⚠️ Gemini API key is not set."
|
144 |
if not model_name:
|
|
|
145 |
return "⚠️ Please select a Gemini model."
|
146 |
try:
|
147 |
genai.configure(api_key=api_key)
|
|
|
229 |
# FIX: Added *args, **kwargs to accept any extra arguments passed by Gradio chaining
|
230 |
def check_send_button_ready(profile: gr.OAuthProfile | None, token: gr.OAuthToken | None, api_key: str | None, model_name: str | None, *args, **kwargs) -> gr.update:
|
231 |
"""Checks if HF login and Gemini configuration are complete and returns update for button interactivity."""
|
232 |
+
# --- START ENHANCED DEBUGGING LOGS ---
|
233 |
+
print("\n--- check_send_button_ready START ---")
|
234 |
+
print(f" Received profile type: {type(profile)}, is None: {profile is None}")
|
235 |
+
print(f" Received token type: {type(token)}, is None: {token is None}")
|
236 |
+
# For api_key, print part of the key if not None for verification, be careful with full key
|
237 |
+
print(f" Received api_key is None: {api_key is None}, first 5 chars: {api_key[:5] if api_key else 'N/A'}")
|
238 |
+
print(f" Received model_name: {model_name}")
|
239 |
+
# --- END ENHANCED DEBUGGING LOGS ---
|
240 |
+
|
241 |
is_logged_in = profile is not None and token is not None
|
242 |
is_gemini_ready = api_key is not None and model_name is not None
|
243 |
+
|
244 |
+
# --- CONTINUED DEBUGGING LOGS ---
|
245 |
+
print(f" HF check: {profile is not None} and {token is not None} = {is_logged_in}")
|
246 |
+
print(f" Gemini check: {api_key is not None} and {model_name is not None} = {is_gemini_ready}")
|
247 |
+
# --- END CONTINUED DEBUGGING LOGS ---
|
248 |
+
|
249 |
is_ready = is_logged_in and is_gemini_ready
|
250 |
print(f"check_send_button_ready - HF Ready: {is_logged_in}, Gemini Ready: {is_gemini_ready}, Button Ready (boolean): {is_ready}")
|
251 |
+
print("--- check_send_button_ready END ---\n")
|
252 |
+
|
253 |
return gr.update(interactive=is_ready)
|
254 |
|
255 |
|
|
|
329 |
if state == STATE_IDLE:
|
330 |
# Check workflow prerequisites before starting any workflow actions
|
331 |
# The Send button should already be disabled if these aren't met, but double-check
|
332 |
+
# Note: These checks here are for the *workflow logic*, not the button interactivity logic.
|
333 |
+
# The button state is controlled by check_send_button_ready and the .then chains.
|
334 |
if not (hf_profile and hf_token):
|
335 |
+
# This case should ideally not be reachable if the button is correctly disabled
|
336 |
history = add_bot_message(history, "Workflow paused: Please log in to Hugging Face first.")
|
337 |
yield (history, repo_id, state, updated_preview, updated_run, updated_build,
|
338 |
attempts, app_desc, repo_name, generated_code, use_grounding)
|
339 |
+
return # Stop workflow execution for this click
|
340 |
|
341 |
if not (gemini_api_key and gemini_model):
|
342 |
+
# This case should also ideally not be reachable if the button is correctly disabled
|
|
|
343 |
history = add_bot_message(history, "Workflow cannot start: Please ensure your Gemini API key is entered and a model is selected.")
|
344 |
yield (history, repo_id, state, updated_preview, updated_run, updated_build,
|
345 |
attempts, app_desc, repo_name, generated_code, use_grounding)
|
346 |
+
return # Stop workflow execution for this click
|
347 |
+
|
348 |
|
349 |
# Look for specific commands in the user's message
|
350 |
reset_match = "reset" in message.lower()
|