josondev commited on
Commit
f4729d3
·
verified ·
1 Parent(s): 8a0eb29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -1,4 +1,4 @@
1
- """ Basic Agent Evaluation Runner"""
2
  import os
3
  import inspect
4
  import gradio as gr
@@ -10,14 +10,14 @@ from veryfinal import build_graph
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
- # --- Basic Agent Definition ---
14
- class BasicAgent:
15
- """A langgraph agent."""
16
  def __init__(self):
17
- print("BasicAgent initialized.")
18
  try:
19
  self.graph = build_graph(provider="groq") # Using Groq as default
20
- print("Graph built successfully.")
21
  except Exception as e:
22
  print(f"Error building graph: {e}")
23
  self.graph = None
@@ -66,8 +66,8 @@ class BasicAgent:
66
 
67
  def run_and_submit_all(profile: gr.OAuthProfile | None):
68
  """
69
- Fetches all questions, runs the BasicAgent on them, submits all answers,
70
- and displays the results.
71
  """
72
  # --- Determine HF Space Runtime URL and Repo URL ---
73
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
@@ -85,7 +85,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
85
 
86
  # 1. Instantiate Agent
87
  try:
88
- agent = BasicAgent()
89
  if agent.graph is None:
90
  return "Error: Failed to initialize agent properly", None
91
  except Exception as e:
@@ -115,7 +115,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
115
  # 3. Run your Agent
116
  results_log = []
117
  answers_payload = []
118
- print(f"Running agent on {len(questions_data)} questions...")
119
 
120
  for i, item in enumerate(questions_data):
121
  task_id = item.get("task_id")
@@ -151,7 +151,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
151
 
152
  # 4. Prepare Submission
153
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
154
- status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
155
  print(status_update)
156
 
157
  # 5. Submit
@@ -178,25 +178,31 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
178
 
179
  # --- Build Gradio Interface using Blocks ---
180
  with gr.Blocks() as demo:
181
- gr.Markdown("# LangGraph Agent Evaluation Runner")
182
  gr.Markdown(
183
  """
184
  **Instructions:**
185
  1. Log in to your Hugging Face account using the button below.
186
  2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
187
 
188
- **Agent Features:**
189
- - Uses FAISS vector database for similar question retrieval
190
- - Includes mathematical calculation tools
191
- - Web search capabilities (Tavily, Wikipedia, ArXiv)
192
- - Rate limiting for free tier models
193
- - Best free models: Groq Llama 3.3 70B, Gemini 2.0 Flash, NVIDIA Llama 3.1 70B
 
 
 
 
 
 
194
  """
195
  )
196
 
197
  gr.LoginButton()
198
 
199
- run_button = gr.Button("Run Evaluation & Submit All Answers")
200
 
201
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
202
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
@@ -207,5 +213,5 @@ with gr.Blocks() as demo:
207
  )
208
 
209
  if __name__ == "__main__":
210
- print("\n" + "-"*30 + " App Starting " + "-"*30)
211
  demo.launch(debug=True, share=False)
 
1
+ """ Multi-LLM Agent Evaluation Runner"""
2
  import os
3
  import inspect
4
  import gradio as gr
 
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
+ # --- Enhanced Agent Definition ---
14
+ class EnhancedMultiLLMAgent:
15
+ """A multi-provider LangGraph agent supporting Groq, DeepSeek, and Baidu."""
16
  def __init__(self):
17
+ print("Enhanced Multi-LLM Agent initialized.")
18
  try:
19
  self.graph = build_graph(provider="groq") # Using Groq as default
20
+ print("Multi-LLM Graph built successfully.")
21
  except Exception as e:
22
  print(f"Error building graph: {e}")
23
  self.graph = None
 
66
 
67
  def run_and_submit_all(profile: gr.OAuthProfile | None):
68
  """
69
+ Fetches all questions, runs the Enhanced Multi-LLM Agent on them,
70
+ submits all answers, and displays the results.
71
  """
72
  # --- Determine HF Space Runtime URL and Repo URL ---
73
  space_id = os.getenv("SPACE_ID") # Get the SPACE_ID for sending link to the code
 
85
 
86
  # 1. Instantiate Agent
87
  try:
88
+ agent = EnhancedMultiLLMAgent()
89
  if agent.graph is None:
90
  return "Error: Failed to initialize agent properly", None
91
  except Exception as e:
 
115
  # 3. Run your Agent
116
  results_log = []
117
  answers_payload = []
118
+ print(f"Running Enhanced Multi-LLM agent on {len(questions_data)} questions...")
119
 
120
  for i, item in enumerate(questions_data):
121
  task_id = item.get("task_id")
 
151
 
152
  # 4. Prepare Submission
153
  submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
154
+ status_update = f"Enhanced Multi-LLM Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
155
  print(status_update)
156
 
157
  # 5. Submit
 
178
 
179
  # --- Build Gradio Interface using Blocks ---
180
  with gr.Blocks() as demo:
181
+ gr.Markdown("# Enhanced Multi-LLM Agent Evaluation Runner")
182
  gr.Markdown(
183
  """
184
  **Instructions:**
185
  1. Log in to your Hugging Face account using the button below.
186
  2. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
187
 
188
+ **Enhanced Agent Features:**
189
+ - **Multi-LLM Support**: Groq, DeepSeek, and Baidu ERNIE
190
+ - **Intelligent Routing**: Automatically selects best provider based on query
191
+ - **Mathematical Tools**: Add, subtract, multiply, divide, modulus operations
192
+ - **Web Search**: Tavily and Wikipedia integration
193
+ - **Error Handling**: Robust fallback mechanisms
194
+ - **Rate Limiting**: Optimized for free tier usage
195
+
196
+ **Supported Models:**
197
+ - **Groq**: Llama 3.1 70B Versatile (fast inference)
198
+ - **DeepSeek**: DeepSeek Chat (reasoning-focused)
199
+ - **Baidu**: ERNIE (Chinese language optimized)
200
  """
201
  )
202
 
203
  gr.LoginButton()
204
 
205
+ run_button = gr.Button("Run Evaluation & Submit All Answers", variant="primary")
206
 
207
  status_output = gr.Textbox(label="Run Status / Submission Result", lines=5, interactive=False)
208
  results_table = gr.DataFrame(label="Questions and Agent Answers", wrap=True)
 
213
  )
214
 
215
  if __name__ == "__main__":
216
+ print("\n" + "-"*30 + " Enhanced Multi-LLM Agent Starting " + "-"*30)
217
  demo.launch(debug=True, share=False)