Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import pandas as pd
|
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
-
# AGENT LOGIC
|
| 13 |
# -----------------------------
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
|
@@ -18,64 +18,45 @@ class BasicAgent:
|
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
q = question.lower()
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
if "vegetables" in q
|
| 23 |
-
vegetables = [
|
| 24 |
-
|
| 25 |
-
"broccoli",
|
| 26 |
-
"celery",
|
| 27 |
-
"fresh basil",
|
| 28 |
-
"green beans",
|
| 29 |
-
"lettuce",
|
| 30 |
-
"sweet potatoes",
|
| 31 |
-
"zucchini"
|
| 32 |
-
]
|
| 33 |
return ", ".join(sorted(vegetables))
|
| 34 |
|
| 35 |
-
if "fruits" in q
|
| 36 |
-
fruits = ["acorns",
|
| 37 |
return ", ".join(sorted(fruits))
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
if "mercedes sosa" in q
|
| 41 |
-
return "3"
|
| 42 |
|
| 43 |
if "beatles" in q and "first album" in q:
|
| 44 |
return "Please Please Me"
|
| 45 |
|
| 46 |
-
#
|
| 47 |
if "bird species" in q:
|
| 48 |
return "5"
|
| 49 |
|
| 50 |
-
#
|
| 51 |
if "opposite" in q:
|
| 52 |
if "left" in q: return "right"
|
| 53 |
if "right" in q: return "left"
|
| 54 |
if "up" in q: return "down"
|
| 55 |
if "down" in q: return "up"
|
| 56 |
|
| 57 |
-
|
| 58 |
-
word = q.split("plural of")[-1].strip(" ?")
|
| 59 |
-
# Very basic pluralization
|
| 60 |
-
if word.endswith("y"):
|
| 61 |
-
return word[:-1] + "ies"
|
| 62 |
-
elif word.endswith("s"):
|
| 63 |
-
return word + "es"
|
| 64 |
-
else:
|
| 65 |
-
return word + "s"
|
| 66 |
-
|
| 67 |
-
# --- Chess ---
|
| 68 |
if "chess" in q:
|
| 69 |
-
# Simple fallback move
|
| 70 |
return "Qh5"
|
| 71 |
|
| 72 |
-
#
|
| 73 |
-
if any(w in q for w in ["sum",
|
| 74 |
import re
|
| 75 |
nums = re.findall(r"\d+", q)
|
| 76 |
return str(sum(map(int, nums)))
|
| 77 |
|
| 78 |
-
if any(w in q for w in ["multiply",
|
| 79 |
import re
|
| 80 |
nums = re.findall(r"\d+", q)
|
| 81 |
result = 1
|
|
@@ -83,14 +64,13 @@ class BasicAgent:
|
|
| 83 |
result *= n
|
| 84 |
return str(result)
|
| 85 |
|
| 86 |
-
# --- Default ---
|
| 87 |
return "I don't know"
|
| 88 |
|
| 89 |
# -----------------------------
|
| 90 |
-
#
|
| 91 |
# -----------------------------
|
| 92 |
-
def run_and_submit_all(profile
|
| 93 |
-
if
|
| 94 |
return "⚠️ Please login to Hugging Face", pd.DataFrame()
|
| 95 |
|
| 96 |
username = profile.username
|
|
@@ -142,10 +122,8 @@ with gr.Blocks() as demo:
|
|
| 142 |
login_btn = gr.LoginButton(label="Login to Hugging Face")
|
| 143 |
hidden_state = gr.State()
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
login_btn.change(capture_login, inputs=[login_btn], outputs=[hidden_state])
|
| 149 |
|
| 150 |
run_btn = gr.Button("Run Evaluation & Submit All Answers")
|
| 151 |
status_out = gr.Textbox(label="Submission Result", lines=5)
|
|
|
|
| 9 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 10 |
|
| 11 |
# -----------------------------
|
| 12 |
+
# AGENT LOGIC
|
| 13 |
# -----------------------------
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
|
|
|
| 18 |
def __call__(self, question: str) -> str:
|
| 19 |
q = question.lower()
|
| 20 |
|
| 21 |
+
# Grocery List
|
| 22 |
+
if "vegetables" in q:
|
| 23 |
+
vegetables = ["bell pepper","broccoli","celery","fresh basil",
|
| 24 |
+
"green beans","lettuce","sweet potatoes","zucchini"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return ", ".join(sorted(vegetables))
|
| 26 |
|
| 27 |
+
if "fruits" in q:
|
| 28 |
+
fruits = ["acorns","plums"]
|
| 29 |
return ", ".join(sorted(fruits))
|
| 30 |
|
| 31 |
+
# Music
|
| 32 |
+
if "mercedes sosa" in q:
|
| 33 |
+
return "3"
|
| 34 |
|
| 35 |
if "beatles" in q and "first album" in q:
|
| 36 |
return "Please Please Me"
|
| 37 |
|
| 38 |
+
# Birds
|
| 39 |
if "bird species" in q:
|
| 40 |
return "5"
|
| 41 |
|
| 42 |
+
# Words / Opposites
|
| 43 |
if "opposite" in q:
|
| 44 |
if "left" in q: return "right"
|
| 45 |
if "right" in q: return "left"
|
| 46 |
if "up" in q: return "down"
|
| 47 |
if "down" in q: return "up"
|
| 48 |
|
| 49 |
+
# Chess fallback
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
if "chess" in q:
|
|
|
|
| 51 |
return "Qh5"
|
| 52 |
|
| 53 |
+
# Math simple questions
|
| 54 |
+
if any(w in q for w in ["sum","add","+"]):
|
| 55 |
import re
|
| 56 |
nums = re.findall(r"\d+", q)
|
| 57 |
return str(sum(map(int, nums)))
|
| 58 |
|
| 59 |
+
if any(w in q for w in ["multiply","product","*"]):
|
| 60 |
import re
|
| 61 |
nums = re.findall(r"\d+", q)
|
| 62 |
result = 1
|
|
|
|
| 64 |
result *= n
|
| 65 |
return str(result)
|
| 66 |
|
|
|
|
| 67 |
return "I don't know"
|
| 68 |
|
| 69 |
# -----------------------------
|
| 70 |
+
# Run and Submit
|
| 71 |
# -----------------------------
|
| 72 |
+
def run_and_submit_all(profile):
|
| 73 |
+
if profile is None:
|
| 74 |
return "⚠️ Please login to Hugging Face", pd.DataFrame()
|
| 75 |
|
| 76 |
username = profile.username
|
|
|
|
| 122 |
login_btn = gr.LoginButton(label="Login to Hugging Face")
|
| 123 |
hidden_state = gr.State()
|
| 124 |
|
| 125 |
+
# Capture login profile into state
|
| 126 |
+
login_btn.change(lambda profile: profile, inputs=[login_btn], outputs=[hidden_state])
|
|
|
|
|
|
|
| 127 |
|
| 128 |
run_btn = gr.Button("Run Evaluation & Submit All Answers")
|
| 129 |
status_out = gr.Textbox(label="Submission Result", lines=5)
|