cowrycode commited on
Commit
f819b62
·
verified ·
1 Parent(s): 98f15fb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -11
app.py CHANGED
@@ -21,10 +21,10 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
21
  # --- Basic Agent Definition ---
22
 
23
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
24
- class BasicAgent:
25
- def __init__(self):
26
- print("BasicAgent initialized. . . .")
27
- self.agent = smart_agent()
28
  # self.api_key = os.getenv("HF_TOKEN")
29
  # self.llm = HuggingFaceInferenceAPI(
30
  # model_name="deepseek-ai/DeepSeek-R1-0528",
@@ -38,17 +38,33 @@ class BasicAgent:
38
  # llm=self.llm
39
  # )
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  async def run(self, question: str) -> str:
43
  print(f"Agent received question (first 50 chars): {question[:50]}...")
44
  answer = await self.agent.run(question)
45
- print(f"Agent returning answer: {answer}")
46
  return answer
47
-
48
- def __call__(self, question: str) -> str:
49
- #return asyncio.run(self.run(question))
50
- return self.run(question)
51
- #return self.agent.run(question)
 
52
 
53
  def run_and_submit_all( profile: gr.OAuthProfile | None):
54
  """
@@ -71,7 +87,8 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
71
 
72
  # 1. Instantiate Agent ( modify this part to create your agent)
73
  try:
74
- agent = BasicAgent()
 
75
  except Exception as e:
76
  print(f"Error instantiating agent: {e}")
77
  return f"Error initializing agent: {e}", None
 
21
  # --- Basic Agent Definition ---
22
 
23
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
24
+ # class BasicAgent:
25
+ # def __init__(self):
26
+ # print("BasicAgent initialized. . . .")
27
+ # self.agent = smart_agent()
28
  # self.api_key = os.getenv("HF_TOKEN")
29
  # self.llm = HuggingFaceInferenceAPI(
30
  # model_name="deepseek-ai/DeepSeek-R1-0528",
 
38
  # llm=self.llm
39
  # )
40
 
41
+ # async def run(self, question: str) -> str:
42
+ # print(f"Agent received question (first 50 chars): {question[:50]}...")
43
+ # answer = await self.agent.run(question)
44
+ # print(f"Agent returning answer: {answer}")
45
+ # return answer
46
+
47
+ # def __call__(self, question: str) -> str:
48
+ # #return asyncio.run(self.run(question))
49
+ # return self.run(question)
50
+ # #return self.agent.run(question)
51
+
52
+ class BasicAgent:
53
+ def __init__(self, agent):
54
+ self.agent = agent
55
+ print("✅ BasicAgent initialized successfully.")
56
 
57
  async def run(self, question: str) -> str:
58
  print(f"Agent received question (first 50 chars): {question[:50]}...")
59
  answer = await self.agent.run(question)
60
+ print(f"Agent returning answer: {answer[:100]}")
61
  return answer
62
+
63
+ @classmethod
64
+ async def create(cls):
65
+ """Factory method to asynchronously initialise BasicAgent."""
66
+ agent = await smart_agent()
67
+ return cls(agent)
68
 
69
  def run_and_submit_all( profile: gr.OAuthProfile | None):
70
  """
 
87
 
88
  # 1. Instantiate Agent ( modify this part to create your agent)
89
  try:
90
+ #agent = BasicAgent()
91
+ agent = BasicAgent.create()
92
  except Exception as e:
93
  print(f"Error instantiating agent: {e}")
94
  return f"Error initializing agent: {e}", None