Files changed (1) hide show
  1. app.py +63 -4
app.py CHANGED
@@ -4,20 +4,79 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
 
 
 
 
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
 
 
 
 
 
 
 
 
13
  class BasicAgent:
14
  def __init__(self):
15
- print("BasicAgent initialized.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  def __call__(self, question: str) -> str:
17
  print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from agnos.llms import HuggingFaceLLM
8
+ from agnos.agent import Agent
9
+ from agnos.toolkit import (
10
+ PDFReader, CSVReader, ExcelReader, TextReader, XMLReader,
11
+ AudioTranscriber, ImageCaptioner, VideoAnalyzer
12
+ )
13
+
14
  # (Keep Constants as is)
15
  # --- Constants ---
16
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
17
 
18
  # --- Basic Agent Definition ---
19
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
20
+ # class BasicAgent:
21
+ # def __init__(self):
22
+ # print("BasicAgent initialized.")
23
+ # def __call__(self, question: str) -> str:
24
+ # print(f"Agent received question (first 50 chars): {question[:50]}...")
25
+ # fixed_answer = "This is a default answer."
26
+ # print(f"Agent returning fixed answer: {fixed_answer}")
27
+ # return fixed_answer
28
+
29
+
30
  class BasicAgent:
31
  def __init__(self):
32
+ print("Initializing LangGraph-powered agent...")
33
+
34
+ # System prompt as per GAIA spec
35
+ system_prompt = (
36
+ "You are a general AI assistant. I will ask you a question. Report your thoughts, "
37
+ "and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. "
38
+ "YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list "
39
+ "of numbers and/or strings. If you are asked for a number, don't use comma to write your number "
40
+ "neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, "
41
+ "don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless "
42
+ "specified otherwise. If you are asked for a comma separated list, apply the above rules depending of "
43
+ "whether the element to be put in the list is a number or a string."
44
+ )
45
+
46
+ # Choose your model from Hugging Face (change if needed)
47
+ self.llm = HuggingFaceLLM("meta-llama/Meta-Llama-3.1-8B-Instruct", system_prompt=system_prompt)
48
+
49
+ # Attach tools
50
+ self.agent = Agent(
51
+ llm=self.llm,
52
+ tools=[
53
+ PDFReader(),
54
+ CSVReader(),
55
+ ExcelReader(),
56
+ TextReader(),
57
+ XMLReader(),
58
+ AudioTranscriber(),
59
+ ImageCaptioner(),
60
+ VideoAnalyzer()
61
+ ]
62
+ )
63
+
64
  def __call__(self, question: str) -> str:
65
  print(f"Agent received question (first 50 chars): {question[:50]}...")
66
+
67
+ try:
68
+ result = self.agent.run(question)
69
+ print(f"Raw result: {result}")
70
+ if "FINAL ANSWER:" in result:
71
+ final_answer = result.split("FINAL ANSWER:")[-1].strip().split("\n")[0]
72
+ print(f"Agent returning final answer: {final_answer}")
73
+ return final_answer
74
+ else:
75
+ return "Could not extract final answer."
76
+ except Exception as e:
77
+ print("Error during agent execution.")
78
+ return f"AGENT ERROR: {e}"
79
+
80
 
81
  def run_and_submit_all( profile: gr.OAuthProfile | None):
82
  """