LamiaYT commited on
Commit
00d5f94
·
1 Parent(s): 165eb7d

Last approach

Browse files
Files changed (1) hide show
  1. app.py +64 -11
app.py CHANGED
@@ -19,7 +19,14 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
19
  # --- Enhanced Custom Tools ---
20
  @tool
21
  def serper_search(query: str) -> str:
22
- """Search the web using Serper API with advanced result filtering"""
 
 
 
 
 
 
 
23
  try:
24
  api_key = os.getenv("SERPER_API_KEY")
25
  if not api_key:
@@ -62,7 +69,14 @@ def serper_search(query: str) -> str:
62
 
63
  @tool
64
  def wikipedia_search(query: str) -> str:
65
- """Wikipedia search with full content extraction"""
 
 
 
 
 
 
 
66
  try:
67
  # Clean query for Wikipedia
68
  clean_query = query.replace(" ", "_")
@@ -114,7 +128,14 @@ def wikipedia_search(query: str) -> str:
114
 
115
  @tool
116
  def enhanced_youtube_analyzer(url: str) -> str:
117
- """YouTube analyzer with transcript extraction and pattern matching"""
 
 
 
 
 
 
 
118
  try:
119
  # Extract video ID
120
  video_id_match = re.search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', url)
@@ -132,7 +153,7 @@ def enhanced_youtube_analyzer(url: str) -> str:
132
  data = response.json()
133
  result = f"Title: {data.get('title', '')}\nAuthor: {data.get('author_name', '')}\n"
134
 
135
- # NEW: Try to get transcript
136
  try:
137
  transcript_url = f"https://youtubetranscript.com/?server_vid={video_id}"
138
  transcript_res = requests.get(transcript_url, timeout=20)
@@ -156,7 +177,15 @@ def enhanced_youtube_analyzer(url: str) -> str:
156
 
157
  @tool
158
  def text_processor(text: str, operation: str = "analyze") -> str:
159
- """Text processing with enhanced operations"""
 
 
 
 
 
 
 
 
160
  try:
161
  if operation == "reverse":
162
  return text[::-1]
@@ -177,7 +206,16 @@ def text_processor(text: str, operation: str = "analyze") -> str:
177
 
178
  @tool
179
  def discography_analyzer(artist: str, start_year: int = None, end_year: int = None) -> str:
180
- """Discography analyzer with chart data verification"""
 
 
 
 
 
 
 
 
 
181
  try:
182
  # Search for discography information
183
  query = f"{artist} discography studio albums"
@@ -218,7 +256,7 @@ def discography_analyzer(artist: str, start_year: int = None, end_year: int = No
218
  for year, album in albums:
219
  result += f"{year}: {album}\n"
220
 
221
- # NEW: Verify with official chart data
222
  try:
223
  chart_url = f"https://musicbrainz.org/ws/2/release-group?artist={artist}&type=album&fmt=json"
224
  chart_res = requests.get(chart_url, headers={'User-Agent': 'GAIA Agent'}, timeout=15)
@@ -246,7 +284,15 @@ def discography_analyzer(artist: str, start_year: int = None, end_year: int = No
246
 
247
  @tool
248
  def data_extractor(source: str, target: str) -> str:
249
- """Enhanced data extractor with expanded classifications"""
 
 
 
 
 
 
 
 
250
  try:
251
  if "botanical" in target.lower():
252
  # EXPANDED classification dictionary
@@ -293,7 +339,14 @@ def data_extractor(source: str, target: str) -> str:
293
 
294
  @tool
295
  def chess_analyzer(description: str) -> str:
296
- """Chess analyzer with position evaluation"""
 
 
 
 
 
 
 
297
  try:
298
  if "black" in description.lower() and "turn" in description.lower():
299
  analysis = "Position Analysis (Black to move):\n"
@@ -307,7 +360,7 @@ def chess_analyzer(description: str) -> str:
307
  elif "attack" in description.lower():
308
  analysis += "\nAttacking Strategy:\n- Target weak squares around enemy king\n- Sacrifice material for initiative\n"
309
 
310
- # NEW: Recommend common defenses
311
  analysis += "\nCommon Defensive Resources:\n"
312
  analysis += "- Pinning attacker pieces\n- Counter-sacrifices\n- Deflection tactics\n"
313
 
@@ -540,7 +593,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
540
  submitted_answer = None
541
  for attempt in range(2):
542
  try:
543
- submitted_answer = EnhancedGAIAAgent()(question_text)
544
  break
545
  except Exception as e:
546
  print(f"Attempt {attempt + 1} failed: {e}")
 
19
  # --- Enhanced Custom Tools ---
20
  @tool
21
  def serper_search(query: str) -> str:
22
+ """Search the web using Serper API with advanced result filtering
23
+
24
+ Args:
25
+ query (str): The search query to execute
26
+
27
+ Returns:
28
+ str: Formatted search results
29
+ """
30
  try:
31
  api_key = os.getenv("SERPER_API_KEY")
32
  if not api_key:
 
69
 
70
  @tool
71
  def wikipedia_search(query: str) -> str:
72
+ """Wikipedia search with full content extraction
73
+
74
+ Args:
75
+ query (str): The Wikipedia search query
76
+
77
+ Returns:
78
+ str: Wikipedia search results with content
79
+ """
80
  try:
81
  # Clean query for Wikipedia
82
  clean_query = query.replace(" ", "_")
 
128
 
129
  @tool
130
  def enhanced_youtube_analyzer(url: str) -> str:
131
+ """YouTube analyzer with transcript extraction and pattern matching
132
+
133
+ Args:
134
+ url (str): YouTube video URL to analyze
135
+
136
+ Returns:
137
+ str: Detailed video analysis
138
+ """
139
  try:
140
  # Extract video ID
141
  video_id_match = re.search(r'(?:v=|\/)([0-9A-Za-z_-]{11}).*', url)
 
153
  data = response.json()
154
  result = f"Title: {data.get('title', '')}\nAuthor: {data.get('author_name', '')}\n"
155
 
156
+ # Try to get transcript
157
  try:
158
  transcript_url = f"https://youtubetranscript.com/?server_vid={video_id}"
159
  transcript_res = requests.get(transcript_url, timeout=20)
 
177
 
178
  @tool
179
  def text_processor(text: str, operation: str = "analyze") -> str:
180
+ """Text processing with enhanced operations
181
+
182
+ Args:
183
+ text (str): Text to process
184
+ operation (str): Processing operation to perform
185
+
186
+ Returns:
187
+ str: Processed text result
188
+ """
189
  try:
190
  if operation == "reverse":
191
  return text[::-1]
 
206
 
207
  @tool
208
  def discography_analyzer(artist: str, start_year: int = None, end_year: int = None) -> str:
209
+ """Discography analyzer with chart data verification
210
+
211
+ Args:
212
+ artist (str): Artist name to analyze
213
+ start_year (int): Optional start year filter
214
+ end_year (int): Optional end year filter
215
+
216
+ Returns:
217
+ str: Discography analysis results
218
+ """
219
  try:
220
  # Search for discography information
221
  query = f"{artist} discography studio albums"
 
256
  for year, album in albums:
257
  result += f"{year}: {album}\n"
258
 
259
+ # Verify with official chart data
260
  try:
261
  chart_url = f"https://musicbrainz.org/ws/2/release-group?artist={artist}&type=album&fmt=json"
262
  chart_res = requests.get(chart_url, headers={'User-Agent': 'GAIA Agent'}, timeout=15)
 
284
 
285
  @tool
286
  def data_extractor(source: str, target: str) -> str:
287
+ """Enhanced data extractor with expanded classifications
288
+
289
+ Args:
290
+ source (str): Source data to extract from
291
+ target (str): Target data to extract
292
+
293
+ Returns:
294
+ str: Extracted data results
295
+ """
296
  try:
297
  if "botanical" in target.lower():
298
  # EXPANDED classification dictionary
 
339
 
340
  @tool
341
  def chess_analyzer(description: str) -> str:
342
+ """Chess analyzer with position evaluation
343
+
344
+ Args:
345
+ description (str): Description of chess position
346
+
347
+ Returns:
348
+ str: Chess analysis and recommendations
349
+ """
350
  try:
351
  if "black" in description.lower() and "turn" in description.lower():
352
  analysis = "Position Analysis (Black to move):\n"
 
360
  elif "attack" in description.lower():
361
  analysis += "\nAttacking Strategy:\n- Target weak squares around enemy king\n- Sacrifice material for initiative\n"
362
 
363
+ # Recommend common defenses
364
  analysis += "\nCommon Defensive Resources:\n"
365
  analysis += "- Pinning attacker pieces\n- Counter-sacrifices\n- Deflection tactics\n"
366
 
 
593
  submitted_answer = None
594
  for attempt in range(2):
595
  try:
596
+ submitted_answer = agent(question_text)
597
  break
598
  except Exception as e:
599
  print(f"Attempt {attempt + 1} failed: {e}")