Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -778,9 +778,8 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
778 |
else:
|
779 |
print("[INFO] Fetching questions...")
|
780 |
response = requests.get(questions_url, timeout=30)
|
781 |
-
print_coso(f"questions: {response}")
|
782 |
response.raise_for_status()
|
783 |
-
print_coso(f"\n\n\n\questions.json: {response.json}")
|
784 |
total_questions = process_questions(response.json())
|
785 |
|
786 |
questions_data = total_questions[:20]
|
@@ -895,7 +894,35 @@ def print_cached_submission(profile: gr.OAuthProfile | None):
|
|
895 |
except Exception as e:
|
896 |
return f"β Could not load cached submission: {e}", None
|
897 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
898 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
899 |
|
900 |
|
901 |
# --- Build Gradio Interface using Blocks ---
|
@@ -919,12 +946,18 @@ with gr.Blocks() as demo:
|
|
919 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
920 |
retry_button = gr.Button("π Retry Last Submission")
|
921 |
print_cache_button = gr.Button("π Show Cached Submission")
|
|
|
922 |
|
923 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
|
|
924 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
925 |
|
926 |
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
927 |
retry_button.click(fn=retry_submission, outputs=[status_output, results_table])
|
|
|
|
|
|
|
|
|
928 |
print_cache_button.click(fn=print_cached_submission, outputs=[status_output, results_table])
|
929 |
|
930 |
if __name__ == "__main__":
|
|
|
778 |
else:
|
779 |
print("[INFO] Fetching questions...")
|
780 |
response = requests.get(questions_url, timeout=30)
|
|
|
781 |
response.raise_for_status()
|
782 |
+
print_coso(f"\n\n\n\questions.json: {response.json()}")
|
783 |
total_questions = process_questions(response.json())
|
784 |
|
785 |
questions_data = total_questions[:20]
|
|
|
894 |
except Exception as e:
|
895 |
return f"β Could not load cached submission: {e}", None
|
896 |
|
897 |
+
def fetch_and_display_questions() -> str:
|
898 |
+
"""
|
899 |
+
Fetches the list of questions from the GAIA service and returns them in JSON-like format.
|
900 |
+
Also logs them to the console.
|
901 |
+
"""
|
902 |
+
api_url = os.getenv("DEFAULT_API_URL", "https://agents-course-unit4-scoring.hf.space")
|
903 |
+
questions_url = f"{api_url}/questions"
|
904 |
|
905 |
+
try:
|
906 |
+
response = requests.get(questions_url, timeout=30)
|
907 |
+
response.raise_for_status()
|
908 |
+
questions = response.json()
|
909 |
+
|
910 |
+
# Filtra le domande nel formato richiesto
|
911 |
+
minimal_format = [
|
912 |
+
{
|
913 |
+
"task_id": q.get("task_id"),
|
914 |
+
"question": q.get("question"),
|
915 |
+
"Level": q.get("Level"),
|
916 |
+
"file_name": q.get("file_name", "")
|
917 |
+
} for q in questions
|
918 |
+
]
|
919 |
+
|
920 |
+
output = json.dumps(minimal_format, indent=4)
|
921 |
+
print_coso("[QUESTIONS FETCHED]")
|
922 |
+
print_coso(output)
|
923 |
+
return output
|
924 |
+
except Exception as e:
|
925 |
+
error_message = f"Error fetching questions: {e}"
|
926 |
|
927 |
|
928 |
# --- Build Gradio Interface using Blocks ---
|
|
|
946 |
run_button = gr.Button("Run Evaluation & Submit All Answers")
|
947 |
retry_button = gr.Button("π Retry Last Submission")
|
948 |
print_cache_button = gr.Button("π Show Cached Submission")
|
949 |
+
fetch_button = gr.Button("π₯ Fetch Questions from Server")
|
950 |
|
951 |
status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
|
952 |
+
question_output = gr.Textbox(label="Fetched Questions", lines=20, interactive=False)
|
953 |
results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
|
954 |
|
955 |
run_button.click(fn=run_and_submit_all, outputs=[status_output, results_table])
|
956 |
retry_button.click(fn=retry_submission, outputs=[status_output, results_table])
|
957 |
+
fetch_button.click(
|
958 |
+
fn=fetch_and_display_questions,
|
959 |
+
outputs=question_output
|
960 |
+
)
|
961 |
print_cache_button.click(fn=print_cached_submission, outputs=[status_output, results_table])
|
962 |
|
963 |
if __name__ == "__main__":
|