GattoNero commited on
Commit
1272c35
·
verified ·
1 Parent(s): ed53926

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -24
app.py CHANGED
@@ -54,15 +54,7 @@ class BasicAgent:
54
  fn=extract_ingredients,
55
  description="Extracts and returns a comma-separated, alphabetized list of ingredients for a pie filling from a transcription string."
56
  )
57
-
58
- chess_tool = FunctionTool.from_defaults(
59
- name="chess_move",
60
- fn=chess_move,
61
- description="Analyzes a chess image and returns the correct move to win"
62
- )
63
-
64
 
65
-
66
  # Registra il tool
67
  Settings.tools = [ingredient_tool, chess_tool]
68
 
@@ -73,7 +65,7 @@ class BasicAgent:
73
  )
74
 
75
  # Prepara l'agente
76
- self.agent = OpenAIAgent.from_tools([ingredient_tool, chess_tool], llm=llm, verbose=True)
77
 
78
  # Client OpenAI per chiamate esterne (immagini/audio)
79
 
@@ -144,6 +136,16 @@ class BasicAgent:
144
  else:
145
  risposta = "Error loading audio file"
146
 
 
 
 
 
 
 
 
 
 
 
147
  elif file_info.endswith(".txt"):
148
  print("coso Text file detected")
149
  text_content = self._load_text(file_info)
@@ -314,7 +316,25 @@ def get_or_download_audio(file_name: str) -> bytes:
314
  print(f"[ERRORE] Impossibile leggere il file audio {file_path}: {e}")
315
  return None
316
 
 
 
 
 
 
 
317
 
 
 
 
 
 
 
 
 
 
 
 
 
318
 
319
  '''
320
  base_url = "https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve"
@@ -358,13 +378,12 @@ def create_mock_questions():
358
 
359
 
360
  return [
361
- {
362
- "task_id":"cca530fc-4052-43b2-b130-b30968d8aa44",
363
- "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.",
364
- "Level":"1",
365
- "file_name":"cca530fc-4052-43b2-b130-b30968d8aa44.png"
366
- }
367
-
368
  ]
369
 
370
 
@@ -398,13 +417,7 @@ def extract_ingredients(transcription: str) -> str:
398
  # normalizza, rimuove duplicati e ordina
399
  unique_ingredients = sorted(set(match.strip() for match in matches))
400
  return ", ".join(unique_ingredients)
401
-
402
- def chess_move() -> str:
403
- """
404
- Analyses a chess image and returns the correct move to win
405
- """
406
- print_coso("tool chess_move")
407
- return 'Qxa5'
408
 
409
  def print_coso(scritta: str):
410
  print(f"coso {scritta}")
@@ -490,7 +503,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
490
  try:
491
  file_name = item.get("file_name")
492
  print_coso(f"file_name riga in 3. Run your Agent: {file_name}")
493
- submitted_answer = 'Qg2+'#agent(question_text, file_name)
494
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
495
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
496
  except Exception as e:
 
54
  fn=extract_ingredients,
55
  description="Extracts and returns a comma-separated, alphabetized list of ingredients for a pie filling from a transcription string."
56
  )
 
 
 
 
 
 
 
57
 
 
58
  # Registra il tool
59
  Settings.tools = [ingredient_tool, chess_tool]
60
 
 
65
  )
66
 
67
  # Prepara l'agente
68
+ self.agent = OpenAIAgent.from_tools([ingredient_tool], llm=llm, verbose=True)
69
 
70
  # Client OpenAI per chiamate esterne (immagini/audio)
71
 
 
136
  else:
137
  risposta = "Error loading audio file"
138
 
139
+ elif file_info.endswith(".py"):
140
+ print_coso("Python code file detected")
141
+ code_content = get_or_download_code(file_info)
142
+ prompt = (
143
+ "The following Python code is attached. Please analyze it and provide only the final output:\n\n"
144
+ f"{code_content}\n\n"
145
+ f"Question: {question}"
146
+ )
147
+ risposta = self._ask_gpt4o(prompt)
148
+
149
  elif file_info.endswith(".txt"):
150
  print("coso Text file detected")
151
  text_content = self._load_text(file_info)
 
316
  print(f"[ERRORE] Impossibile leggere il file audio {file_path}: {e}")
317
  return None
318
 
319
+ def get_or_download_code(file_name: str) -> str:
320
+ import os
321
+ import requests
322
+
323
+ file_path = os.path.join("data", file_name)
324
+ hf_token = os.getenv("HF_TOKEN_READ")
325
 
326
+ if not os.path.exists(file_path):
327
+ print(f"[INFO] File {file_name} non trovato. Scarico...")
328
+ url = f"https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve/main/2023/validation/{file_name}"
329
+ headers = {"Authorization": f"Bearer {hf_token}"}
330
+ response = requests.get(url, headers=headers)
331
+ response.raise_for_status()
332
+ with open(file_path, "wb") as f:
333
+ f.write(response.content)
334
+ print(f"[INFO] Scaricato in {file_path}")
335
+
336
+ with open(file_path, "r") as f:
337
+ return f.read()
338
 
339
  '''
340
  base_url = "https://huggingface.co/datasets/gaia-benchmark/GAIA/resolve"
 
378
 
379
 
380
  return [
381
+ {
382
+ "task_id":"f918266a-b3e0-4914-865d-4faa564f1aef",
383
+ "question":"What is the final numeric output from the attached Python code?",
384
+ "Level":"1",
385
+ "file_name":"f918266a-b3e0-4914-865d-4faa564f1aef.py"
386
+ }
 
387
  ]
388
 
389
 
 
417
  # normalizza, rimuove duplicati e ordina
418
  unique_ingredients = sorted(set(match.strip() for match in matches))
419
  return ", ".join(unique_ingredients)
420
+
 
 
 
 
 
 
421
 
422
  def print_coso(scritta: str):
423
  print(f"coso {scritta}")
 
503
  try:
504
  file_name = item.get("file_name")
505
  print_coso(f"file_name riga in 3. Run your Agent: {file_name}")
506
+ submitted_answer = agent(question_text, file_name)
507
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
508
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
509
  except Exception as e: