Spaces:
Sleeping
Sleeping
Disabled some prints.
Browse files- agent_tools.py +1 -1
- app.py +42 -25
agent_tools.py
CHANGED
@@ -109,7 +109,7 @@ def langsearch_search(query: str, count: int = 5) -> list:
|
|
109 |
results = []
|
110 |
for result in response["data"]["webPages"]["value"]:
|
111 |
results.append(result["summary"])
|
112 |
-
print(f"LangSearch results: {results}")
|
113 |
return results
|
114 |
except Exception as e:
|
115 |
print(f"Error during LangSearch search: {e}")
|
|
|
109 |
results = []
|
110 |
for result in response["data"]["webPages"]["value"]:
|
111 |
results.append(result["summary"])
|
112 |
+
#print(f"LangSearch results: {results}")
|
113 |
return results
|
114 |
except Exception as e:
|
115 |
print(f"Error during LangSearch search: {e}")
|
app.py
CHANGED
@@ -13,6 +13,8 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
13 |
|
14 |
# --- Basic Agent Definition ---
|
15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
16 |
class BasicAgent:
|
17 |
def __init__(self):
|
18 |
print("BasicAgent initialized.")
|
@@ -30,25 +32,40 @@ class BasicAgent:
|
|
30 |
nlp = spacy.load("en_core_web_sm")
|
31 |
doc = nlp(question)
|
32 |
keywords = [token.text for token in doc if token.pos_ in ['NOUN', 'PROPN']]
|
33 |
-
entities = entities = [
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
# Call langsearch_search function
|
38 |
-
#search_results = langsearch_search(query=question, count=10)
|
39 |
# Use entities for search if available, otherwise use the original question
|
40 |
search_query = ""
|
41 |
if entities:
|
42 |
search_query = " ".join(entities)
|
43 |
-
print(f"Using entities for search query: '{search_query}'")
|
44 |
else:
|
45 |
# Fallback: If no specific entities are found, use keywords or the original question
|
46 |
if keywords:
|
47 |
search_query = " ".join(keywords)
|
48 |
-
print(f"No entities found, using keywords for search query: '{search_query}'")
|
49 |
else:
|
50 |
search_query = question
|
51 |
-
print("No entities or keywords found, using original question for search query.")
|
52 |
search_results = langsearch_search(query=search_query, count=10)
|
53 |
if len(search_results) > 0:
|
54 |
# Convert search results to a readable text format
|
@@ -194,12 +211,12 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
194 |
# 'Level': '1',
|
195 |
# 'file_name': ''
|
196 |
# },
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
# {
|
204 |
# 'task_id': 'cca530fc-4052-43b2-b130-b30968d8aa44',
|
205 |
# 'question': "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
@@ -254,12 +271,12 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
254 |
# 'Level': '1',
|
255 |
# 'file_name': 'f918266a-b3e0-4914-865d-4faa564f1aef.py'
|
256 |
# },
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
# {
|
264 |
# 'task_id': '1f975693-876d-457b-a649-393859e79bf3',
|
265 |
# 'question': "Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.",
|
@@ -296,12 +313,12 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
296 |
# 'Level': '1',
|
297 |
# 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'
|
298 |
# },
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
]
|
306 |
|
307 |
# 3. Run your Agent
|
|
|
13 |
|
14 |
# --- Basic Agent Definition ---
|
15 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
16 |
+
|
17 |
+
|
18 |
class BasicAgent:
|
19 |
def __init__(self):
|
20 |
print("BasicAgent initialized.")
|
|
|
32 |
nlp = spacy.load("en_core_web_sm")
|
33 |
doc = nlp(question)
|
34 |
keywords = [token.text for token in doc if token.pos_ in ['NOUN', 'PROPN']]
|
35 |
+
entities = entities = [
|
36 |
+
ent.text for ent in doc.ents if ent.label_ in [
|
37 |
+
'PRODUCT',
|
38 |
+
'WORK_OF_ART',
|
39 |
+
'EVENT',
|
40 |
+
'ORG',
|
41 |
+
'FAC',
|
42 |
+
'GPE',
|
43 |
+
'NORP',
|
44 |
+
'LOC',
|
45 |
+
'LANGUAGE',
|
46 |
+
'PERSON',
|
47 |
+
'DATE',
|
48 |
+
'TIME',
|
49 |
+
'MONEY',
|
50 |
+
'LAW']]
|
51 |
+
#print("Keywords:", keywords)
|
52 |
+
#print("Entities:", entities)
|
53 |
|
54 |
# Call langsearch_search function
|
55 |
+
# search_results = langsearch_search(query=question, count=10)
|
56 |
# Use entities for search if available, otherwise use the original question
|
57 |
search_query = ""
|
58 |
if entities:
|
59 |
search_query = " ".join(entities)
|
60 |
+
#print(f"Using entities for search query: '{search_query}'")
|
61 |
else:
|
62 |
# Fallback: If no specific entities are found, use keywords or the original question
|
63 |
if keywords:
|
64 |
search_query = " ".join(keywords)
|
65 |
+
#print(f"No entities found, using keywords for search query: '{search_query}'")
|
66 |
else:
|
67 |
search_query = question
|
68 |
+
#print("No entities or keywords found, using original question for search query.")
|
69 |
search_results = langsearch_search(query=search_query, count=10)
|
70 |
if len(search_results) > 0:
|
71 |
# Convert search results to a readable text format
|
|
|
211 |
# 'Level': '1',
|
212 |
# 'file_name': ''
|
213 |
# },
|
214 |
+
{
|
215 |
+
'task_id': '2d83110e-a098-4ebb-9987-066c06fa42d0',
|
216 |
+
'question': '.rewsna eht sa "tfel" drow eht fo etisoppo eht etirw ,ecnetnes siht dnatsrednu uoy fI',
|
217 |
+
'Level': '1',
|
218 |
+
'file_name': ''
|
219 |
+
},
|
220 |
# {
|
221 |
# 'task_id': 'cca530fc-4052-43b2-b130-b30968d8aa44',
|
222 |
# 'question': "Review the chess position provided in the image. It is black's turn. Provide the correct next move for black which guarantees a win. Please provide your response in algebraic notation.",
|
|
|
271 |
# 'Level': '1',
|
272 |
# 'file_name': 'f918266a-b3e0-4914-865d-4faa564f1aef.py'
|
273 |
# },
|
274 |
+
{
|
275 |
+
'task_id': '3f57289b-8c60-48be-bd80-01f8099ca449',
|
276 |
+
'question': 'How many at bats did the Yankee with the most walks in the 1977 regular season have that same season?',
|
277 |
+
'Level': '1',
|
278 |
+
'file_name': ''
|
279 |
+
},
|
280 |
# {
|
281 |
# 'task_id': '1f975693-876d-457b-a649-393859e79bf3',
|
282 |
# 'question': "Hi, I was out sick from my classes on Friday, so I'm trying to figure out what I need to study for my Calculus mid-term next week. My friend from class sent me an audio recording of Professor Willowbrook giving out the recommended reading for the test, but my headphones are broken :(\n\nCould you please listen to the recording for me and tell me the page numbers I'm supposed to go over? I've attached a file called Homework.mp3 that has the recording. Please provide just the page numbers as a comma-delimited list. And please provide the list in ascending order.",
|
|
|
313 |
# 'Level': '1',
|
314 |
# 'file_name': '7bd855d8-463d-4ed5-93ca-5fe35145f733.xlsx'
|
315 |
# },
|
316 |
+
{
|
317 |
+
'task_id': '5a0c1adf-205e-4841-a666-7c3ef95def9d',
|
318 |
+
'question': 'What is the first name of the only Malko Competition recipient from the 20th Century (after 1977) whose nationality on record is a country that no longer exists?',
|
319 |
+
'Level': '1',
|
320 |
+
'file_name': ''
|
321 |
+
},
|
322 |
]
|
323 |
|
324 |
# 3. Run your Agent
|