Spaces:
Sleeping
Sleeping
KoRiF
commited on
Commit
·
67479b4
1
Parent(s):
0f1e5fd
Debug configuration for GAIAAnsweringWorkflow-based app
Browse files
app.py
CHANGED
|
@@ -3,6 +3,11 @@ import gradio as gr
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -10,14 +15,16 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 10 |
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
-
class
|
| 14 |
def __init__(self):
|
| 15 |
-
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
@@ -40,7 +47,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 40 |
|
| 41 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 42 |
try:
|
| 43 |
-
agent =
|
| 44 |
except Exception as e:
|
| 45 |
print(f"Error instantiating agent: {e}")
|
| 46 |
return f"Error initializing agent: {e}", None
|
|
@@ -58,13 +65,13 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 58 |
print("Fetched questions list is empty.")
|
| 59 |
return "Fetched questions list is empty or invalid format.", None
|
| 60 |
print(f"Fetched {len(questions_data)} questions.")
|
| 61 |
-
except requests.exceptions.RequestException as e:
|
| 62 |
-
print(f"Error fetching questions: {e}")
|
| 63 |
-
return f"Error fetching questions: {e}", None
|
| 64 |
except requests.exceptions.JSONDecodeError as e:
|
| 65 |
print(f"Error decoding JSON response from questions endpoint: {e}")
|
| 66 |
print(f"Response text: {response.text[:500]}")
|
| 67 |
return f"Error decoding server response for questions: {e}", None
|
|
|
|
|
|
|
|
|
|
| 68 |
except Exception as e:
|
| 69 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 70 |
return f"An unexpected error occurred fetching questions: {e}", None
|
|
@@ -90,12 +97,19 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 90 |
if not answers_payload:
|
| 91 |
print("Agent did not produce any answers to submit.")
|
| 92 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
| 94 |
# 4. Prepare Submission
|
| 95 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 96 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 97 |
print(status_update)
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
# 5. Submit
|
| 100 |
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 101 |
try:
|
|
|
|
| 3 |
import requests
|
| 4 |
import inspect
|
| 5 |
import pandas as pd
|
| 6 |
+
from workflow import GAIAAnsweringWorkflow
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
load_dotenv()
|
| 11 |
|
| 12 |
# (Keep Constants as is)
|
| 13 |
# --- Constants ---
|
|
|
|
| 15 |
|
| 16 |
# --- Basic Agent Definition ---
|
| 17 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 18 |
+
class JeSaisToutAgent(GAIAAnsweringWorkflow):
|
| 19 |
def __init__(self):
|
| 20 |
+
super().__init__()
|
| 21 |
+
print("Agentics Workflow initialized.")
|
| 22 |
def __call__(self, question: str) -> str:
|
| 23 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 24 |
+
answer = "This is a default answer."
|
| 25 |
+
answer=super().__call__(question)
|
| 26 |
+
print(f"Agent returning answer: {answer}")
|
| 27 |
+
return answer
|
| 28 |
|
| 29 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 30 |
"""
|
|
|
|
| 47 |
|
| 48 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 49 |
try:
|
| 50 |
+
agent = JeSaisToutAgent()
|
| 51 |
except Exception as e:
|
| 52 |
print(f"Error instantiating agent: {e}")
|
| 53 |
return f"Error initializing agent: {e}", None
|
|
|
|
| 65 |
print("Fetched questions list is empty.")
|
| 66 |
return "Fetched questions list is empty or invalid format.", None
|
| 67 |
print(f"Fetched {len(questions_data)} questions.")
|
|
|
|
|
|
|
|
|
|
| 68 |
except requests.exceptions.JSONDecodeError as e:
|
| 69 |
print(f"Error decoding JSON response from questions endpoint: {e}")
|
| 70 |
print(f"Response text: {response.text[:500]}")
|
| 71 |
return f"Error decoding server response for questions: {e}", None
|
| 72 |
+
except requests.exceptions.RequestException as e:
|
| 73 |
+
print(f"Error fetching questions: {e}")
|
| 74 |
+
return f"Error fetching questions: {e}", None
|
| 75 |
except Exception as e:
|
| 76 |
print(f"An unexpected error occurred fetching questions: {e}")
|
| 77 |
return f"An unexpected error occurred fetching questions: {e}", None
|
|
|
|
| 97 |
if not answers_payload:
|
| 98 |
print("Agent did not produce any answers to submit.")
|
| 99 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
| 100 |
+
if os.getenv("TESTRUN"):
|
| 101 |
+
print("Skipping submission in test environment.")
|
| 102 |
+
return "Skipping submission in test environment.", pd.DataFrame(results_log)
|
| 103 |
+
|
| 104 |
# 4. Prepare Submission
|
| 105 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
| 106 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
| 107 |
print(status_update)
|
| 108 |
+
|
| 109 |
+
if os.getenv("TESTRUN"):
|
| 110 |
+
print(f"Skipping submission in test environment. \n{submission_data}")
|
| 111 |
+
return "Skipping submission in test environment.", pd.DataFrame(submission_data)
|
| 112 |
+
|
| 113 |
# 5. Submit
|
| 114 |
print(f"Submitting {len(answers_payload)} answers to: {submit_url}")
|
| 115 |
try:
|