anandshende-videocx commited on
Commit
02c7268
·
verified ·
1 Parent(s): 81917a3
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -4,6 +4,13 @@ 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"
@@ -12,13 +19,31 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
  """
24
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ import os
8
+ import asyncio
9
+ from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
10
+ from llama_index.tools.arxiv import ArxivToolSpec
11
+ from llama_index.core.agent.workflow import AgentWorkflow
12
+ from llama_index.core.tools import FunctionTool
13
+
14
  # (Keep Constants as is)
15
  # --- Constants ---
16
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
19
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
20
  class BasicAgent:
21
  def __init__(self):
22
+ llm = HuggingFaceInferenceAPI(
23
+ model_name="Qwen/Qwen2.5-Coder-32B-Instruct",
24
+ )
25
+
26
+ self.agent = AgentWorkflow.from_tools_or_functions(
27
+ [
28
+ *ArxivToolSpec().to_tool_list(),
29
+ ],
30
+ llm=llm,
31
+ )
32
+
33
  print("BasicAgent initialized.")
34
+
35
  def __call__(self, question: str) -> str:
36
  print(f"Agent received question (first 50 chars): {question[:50]}...")
37
+
38
+ fixed_answer = asyncio.run(self.generate_answer(question))
39
+
40
  print(f"Agent returning fixed answer: {fixed_answer}")
41
  return fixed_answer
42
 
43
+ async def generate_answer(self, question: str) -> str:
44
+ response = await self.agent.run(question)
45
+ return response
46
+
47
  def run_and_submit_all( profile: gr.OAuthProfile | None):
48
  """
49
  Fetches all questions, runs the BasicAgent on them, submits all answers,