Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -34,13 +34,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
34 |
questions_url = f"{api_url}/questions"
|
35 |
submit_url = f"{api_url}/submit"
|
36 |
|
37 |
-
# 1. Instantiate Agent
|
38 |
try:
|
39 |
agent = BasicAgent()
|
40 |
except Exception as e:
|
41 |
print(f"Error instantiating agent: {e}")
|
42 |
return f"Error initializing agent: {e}", None
|
43 |
-
|
44 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
45 |
print(agent_code)
|
46 |
|
@@ -59,7 +59,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
59 |
return f"Error fetching questions: {e}", None
|
60 |
except requests.exceptions.JSONDecodeError as e:
|
61 |
print(f"Error decoding JSON response from questions endpoint: {e}")
|
62 |
-
print(f"Response text: {response.text[:500]}")
|
63 |
return f"Error decoding server response for questions: {e}", None
|
64 |
except Exception as e:
|
65 |
print(f"An unexpected error occurred fetching questions: {e}")
|
@@ -119,24 +118,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
119 |
print(status_message)
|
120 |
results_df = pd.DataFrame(results_log)
|
121 |
return status_message, results_df
|
122 |
-
except requests.exceptions.Timeout:
|
123 |
-
status_message = "Submission Failed: The request timed out."
|
124 |
-
print(status_message)
|
125 |
-
results_df = pd.DataFrame(results_log)
|
126 |
-
return status_message, results_df
|
127 |
except requests.exceptions.RequestException as e:
|
128 |
status_message = f"Submission Failed: Network error - {e}"
|
129 |
print(status_message)
|
130 |
results_df = pd.DataFrame(results_log)
|
131 |
return status_message, results_df
|
132 |
-
except Exception as e:
|
133 |
-
status_message = f"An unexpected error occurred during submission: {e}"
|
134 |
-
print(status_message)
|
135 |
-
results_df = pd.DataFrame(results_log)
|
136 |
-
return status_message, results_df
|
137 |
|
138 |
|
139 |
-
# --- Build Gradio Interface using Blocks ---
|
140 |
# --- Build Gradio Interface using Blocks ---
|
141 |
with gr.Blocks() as demo:
|
142 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
@@ -147,15 +135,10 @@ with gr.Blocks() as demo:
|
|
147 |
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
148 |
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
149 |
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
150 |
-
|
151 |
-
---
|
152 |
-
**Disclaimers:**
|
153 |
-
Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
|
154 |
-
This space provides a basic setup and is intentionally sub-optimal to encourage you to develop your own, more robust solution. For instance for the delay process of the submit button, a solution could be to cache the answers and submit in a seperate action or even to answer the questions in async.
|
155 |
"""
|
156 |
)
|
157 |
|
158 |
-
#
|
159 |
login_button = gr.LoginButton()
|
160 |
|
161 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
@@ -163,31 +146,26 @@ with gr.Blocks() as demo:
|
|
163 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
164 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
165 |
|
166 |
-
#
|
167 |
-
# - 'fn' est la fonction à appeler.
|
168 |
-
# - 'inputs' est une liste des composants dont la valeur est passée à 'fn'.
|
169 |
-
# Ici, on passe uniquement le profil de l'utilisateur depuis le bouton de connexion.
|
170 |
-
# - 'outputs' sont les composants qui afficheront le résultat.
|
171 |
run_button.click(
|
172 |
fn=run_and_submit_all,
|
173 |
inputs=[login_button],
|
174 |
outputs=[status_output, results_table]
|
175 |
)
|
176 |
|
|
|
177 |
if __name__ == "__main__":
|
178 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
179 |
-
# Check for SPACE_HOST and SPACE_ID at startup for information
|
180 |
space_host_startup = os.getenv("SPACE_HOST")
|
181 |
-
space_id_startup = os.getenv("SPACE_ID")
|
182 |
|
183 |
if space_host_startup:
|
184 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
185 |
else:
|
186 |
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
187 |
|
188 |
-
if space_id_startup:
|
189 |
print(f"✅ SPACE_ID found: {space_id_startup}")
|
190 |
-
print(f" Repo URL: https://huggingface.co/spaces/{space_id_startup}")
|
191 |
else:
|
192 |
print("ℹ️ SPACE_ID environment variable not found (running locally?).")
|
193 |
|
|
|
34 |
questions_url = f"{api_url}/questions"
|
35 |
submit_url = f"{api_url}/submit"
|
36 |
|
37 |
+
# 1. Instantiate Agent
|
38 |
try:
|
39 |
agent = BasicAgent()
|
40 |
except Exception as e:
|
41 |
print(f"Error instantiating agent: {e}")
|
42 |
return f"Error initializing agent: {e}", None
|
43 |
+
|
44 |
agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
|
45 |
print(agent_code)
|
46 |
|
|
|
59 |
return f"Error fetching questions: {e}", None
|
60 |
except requests.exceptions.JSONDecodeError as e:
|
61 |
print(f"Error decoding JSON response from questions endpoint: {e}")
|
|
|
62 |
return f"Error decoding server response for questions: {e}", None
|
63 |
except Exception as e:
|
64 |
print(f"An unexpected error occurred fetching questions: {e}")
|
|
|
118 |
print(status_message)
|
119 |
results_df = pd.DataFrame(results_log)
|
120 |
return status_message, results_df
|
|
|
|
|
|
|
|
|
|
|
121 |
except requests.exceptions.RequestException as e:
|
122 |
status_message = f"Submission Failed: Network error - {e}"
|
123 |
print(status_message)
|
124 |
results_df = pd.DataFrame(results_log)
|
125 |
return status_message, results_df
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
|
|
|
128 |
# --- Build Gradio Interface using Blocks ---
|
129 |
with gr.Blocks() as demo:
|
130 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
|
|
135 |
1. Please clone this space, then modify the code to define your agent's logic, the tools, the necessary packages, etc ...
|
136 |
2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
|
137 |
3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
|
|
|
|
|
|
|
|
|
|
|
138 |
"""
|
139 |
)
|
140 |
|
141 |
+
# On assigne le bouton de connexion à une variable
|
142 |
login_button = gr.LoginButton()
|
143 |
|
144 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
|
|
146 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
147 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
148 |
|
149 |
+
# On utilise la variable 'login_button' comme 'inputs' pour le clic
|
|
|
|
|
|
|
|
|
150 |
run_button.click(
|
151 |
fn=run_and_submit_all,
|
152 |
inputs=[login_button],
|
153 |
outputs=[status_output, results_table]
|
154 |
)
|
155 |
|
156 |
+
|
157 |
if __name__ == "__main__":
|
158 |
print("\n" + "-"*30 + " App Starting " + "-"*30)
|
|
|
159 |
space_host_startup = os.getenv("SPACE_HOST")
|
160 |
+
space_id_startup = os.getenv("SPACE_ID")
|
161 |
|
162 |
if space_host_startup:
|
163 |
print(f"✅ SPACE_HOST found: {space_host_startup}")
|
164 |
else:
|
165 |
print("ℹ️ SPACE_HOST environment variable not found (running locally?).")
|
166 |
|
167 |
+
if space_id_startup:
|
168 |
print(f"✅ SPACE_ID found: {space_id_startup}")
|
|
|
169 |
else:
|
170 |
print("ℹ️ SPACE_ID environment variable not found (running locally?).")
|
171 |
|