Spaces:
Sleeping
Sleeping
fix: button toggling logic
Browse files
app.py
CHANGED
|
@@ -33,7 +33,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 33 |
print(f"User logged in: {username}")
|
| 34 |
else:
|
| 35 |
print("User not logged in.")
|
| 36 |
-
return "Please Login to Hugging Face with the button.", None
|
| 37 |
|
| 38 |
api_url = DEFAULT_API_URL
|
| 39 |
questions_url = f"{api_url}/questions"
|
|
@@ -46,7 +46,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
print(f"Error instantiating agent: {e}")
|
| 49 |
-
return f"Error initializing agent: {e}", None
|
| 50 |
|
| 51 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 52 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
|
@@ -62,21 +62,21 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 62 |
|
| 63 |
if not questions_data:
|
| 64 |
print("Fetched questions list is empty.")
|
| 65 |
-
return "Fetched questions list is empty or invalid format.", None
|
| 66 |
print(f"Fetched {len(questions_data)} questions.")
|
| 67 |
|
| 68 |
except requests.exceptions.RequestException as e:
|
| 69 |
print(f"Error fetching questions: {e}")
|
| 70 |
-
return f"Error fetching questions: {e}", None
|
| 71 |
|
| 72 |
except requests.exceptions.JSONDecodeError as e:
|
| 73 |
print(f"Error decoding JSON response from questions endpoint: {e}")
|
| 74 |
print(f"Response text: {response.text[:500]}")
|
| 75 |
-
return f"Error decoding server response for questions: {e}", None
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 79 |
-
return f"An unexpected error occurred fetching questions: {e}", None
|
| 80 |
|
| 81 |
|
| 82 |
# 3. Run your Agent
|
|
@@ -103,7 +103,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 103 |
|
| 104 |
if not answers_payload:
|
| 105 |
print("Agent did not produce any answers to submit.")
|
| 106 |
-
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 107 |
|
| 108 |
|
| 109 |
# 4. Prepare Submission
|
|
@@ -128,7 +128,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 128 |
)
|
| 129 |
print("Submission successful.")
|
| 130 |
results_df = pd.DataFrame(results_log)
|
| 131 |
-
return final_status, results_df
|
| 132 |
|
| 133 |
except requests.exceptions.HTTPError as e:
|
| 134 |
error_detail = f"Server responded with status {e.response.status_code}."
|
|
@@ -143,25 +143,25 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 143 |
status_message = f"Submission Failed: {error_detail}"
|
| 144 |
print(status_message)
|
| 145 |
results_df = pd.DataFrame(results_log)
|
| 146 |
-
return status_message, results_df
|
| 147 |
|
| 148 |
except requests.exceptions.Timeout:
|
| 149 |
status_message = "Submission Failed: The request timed out."
|
| 150 |
print(status_message)
|
| 151 |
results_df = pd.DataFrame(results_log)
|
| 152 |
-
return status_message, results_df
|
| 153 |
|
| 154 |
except requests.exceptions.RequestException as e:
|
| 155 |
status_message = f"Submission Failed: Network error - {e}"
|
| 156 |
print(status_message)
|
| 157 |
results_df = pd.DataFrame(results_log)
|
| 158 |
-
return status_message, results_df
|
| 159 |
|
| 160 |
except Exception as e:
|
| 161 |
status_message = f"An unexpected error occurred during submission: {e}"
|
| 162 |
print(status_message)
|
| 163 |
results_df = pd.DataFrame(results_log)
|
| 164 |
-
return status_message, results_df, gr.update(interactive=
|
| 165 |
|
| 166 |
|
| 167 |
def download_log():
|
|
|
|
| 33 |
print(f"User logged in: {username}")
|
| 34 |
else:
|
| 35 |
print("User not logged in.")
|
| 36 |
+
return "Please Login to Hugging Face with the button.", None, gr.update(interactive=False)
|
| 37 |
|
| 38 |
api_url = DEFAULT_API_URL
|
| 39 |
questions_url = f"{api_url}/questions"
|
|
|
|
| 46 |
|
| 47 |
except Exception as e:
|
| 48 |
print(f"Error instantiating agent: {e}")
|
| 49 |
+
return f"Error initializing agent: {e}", None, gr.update(interactive=False)
|
| 50 |
|
| 51 |
# In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
|
| 52 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
|
|
|
| 62 |
|
| 63 |
if not questions_data:
|
| 64 |
print("Fetched questions list is empty.")
|
| 65 |
+
return "Fetched questions list is empty or invalid format.", None, gr.update(interactive=False)
|
| 66 |
print(f"Fetched {len(questions_data)} questions.")
|
| 67 |
|
| 68 |
except requests.exceptions.RequestException as e:
|
| 69 |
print(f"Error fetching questions: {e}")
|
| 70 |
+
return f"Error fetching questions: {e}", None, gr.update(interactive=False)
|
| 71 |
|
| 72 |
except requests.exceptions.JSONDecodeError as e:
|
| 73 |
print(f"Error decoding JSON response from questions endpoint: {e}")
|
| 74 |
print(f"Response text: {response.text[:500]}")
|
| 75 |
+
return f"Error decoding server response for questions: {e}", None, gr.update(interactive=False)
|
| 76 |
|
| 77 |
except Exception as e:
|
| 78 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 79 |
+
return f"An unexpected error occurred fetching questions: {e}", None, gr.update(interactive=False)
|
| 80 |
|
| 81 |
|
| 82 |
# 3. Run your Agent
|
|
|
|
| 103 |
|
| 104 |
if not answers_payload:
|
| 105 |
print("Agent did not produce any answers to submit.")
|
| 106 |
+
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log), gr.update(interactive=False)
|
| 107 |
|
| 108 |
|
| 109 |
# 4. Prepare Submission
|
|
|
|
| 128 |
)
|
| 129 |
print("Submission successful.")
|
| 130 |
results_df = pd.DataFrame(results_log)
|
| 131 |
+
return final_status, results_df, gr.update(interactive=True)
|
| 132 |
|
| 133 |
except requests.exceptions.HTTPError as e:
|
| 134 |
error_detail = f"Server responded with status {e.response.status_code}."
|
|
|
|
| 143 |
status_message = f"Submission Failed: {error_detail}"
|
| 144 |
print(status_message)
|
| 145 |
results_df = pd.DataFrame(results_log)
|
| 146 |
+
return status_message, results_df, gr.update(interactive=False)
|
| 147 |
|
| 148 |
except requests.exceptions.Timeout:
|
| 149 |
status_message = "Submission Failed: The request timed out."
|
| 150 |
print(status_message)
|
| 151 |
results_df = pd.DataFrame(results_log)
|
| 152 |
+
return status_message, results_df, gr.update(interactive=False)
|
| 153 |
|
| 154 |
except requests.exceptions.RequestException as e:
|
| 155 |
status_message = f"Submission Failed: Network error - {e}"
|
| 156 |
print(status_message)
|
| 157 |
results_df = pd.DataFrame(results_log)
|
| 158 |
+
return status_message, results_df, gr.update(interactive=False)
|
| 159 |
|
| 160 |
except Exception as e:
|
| 161 |
status_message = f"An unexpected error occurred during submission: {e}"
|
| 162 |
print(status_message)
|
| 163 |
results_df = pd.DataFrame(results_log)
|
| 164 |
+
return status_message, results_df, gr.update(interactive=False)
|
| 165 |
|
| 166 |
|
| 167 |
def download_log():
|