Update app.py
#477
by joudbaz77 - opened
app.py
CHANGED
|
@@ -12,24 +12,32 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
-
print("
|
|
|
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
| 24 |
-
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
| 25 |
-
and displays the results.
|
| 26 |
-
"""
|
| 27 |
-
# --- Determine HF Space Runtime URL and Repo URL ---
|
| 28 |
-
space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
|
| 29 |
-
|
| 30 |
-
if profile:
|
| 31 |
-
username= f"{profile.username}"
|
| 32 |
-
print(f"User logged in: {username}")
|
| 33 |
else:
|
| 34 |
print("User not logged in.")
|
| 35 |
return "Please Login to Hugging Face with the button.", None
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
print("Agent initialized")
|
| 16 |
+
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
+
try:
|
| 19 |
+
result = real_agent.run(
|
| 20 |
+
"Answer only with the final short exact result. No explanation. No words. Only the final answer.\n\nQuestion:\n"
|
| 21 |
+
+ question
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
result = str(result).strip()
|
| 25 |
+
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
result = str(result).strip()
|
| 29 |
+
|
| 30 |
+
# VERY IMPORTANT: keep only last line (often the real answer)
|
| 31 |
+
result = result.split("\n")[-1]
|
| 32 |
+
|
| 33 |
+
return result
|
| 34 |
+
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print(f"Agent error: {e}")
|
| 37 |
+
return "unknown"
|
| 38 |
|
| 39 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 40 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
print("User not logged in.")
|
| 43 |
return "Please Login to Hugging Face with the button.", None
|