mianf4884 commited on
Commit
8a36d69
·
verified ·
1 Parent(s): a57b3ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -2,7 +2,6 @@ import os
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
- # Fixed Imports for 2026 smolagents version
6
  from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel, VisitWebpageTool
7
 
8
  # --- Constants ---
@@ -11,9 +10,14 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
  # --- Agent Definition ---
12
  class AgentArchitect:
13
  def __init__(self):
14
- # We use LiteLLMModel here - it's the updated, more stable way to call HF models
15
- # and other providers in the current smolagents version.
16
- self.model = LiteLLMModel(model_id="huggingface/Qwen/Qwen2.5-72B-Instruct")
 
 
 
 
 
17
 
18
  self.tools = [DuckDuckGoSearchTool(), VisitWebpageTool()]
19
 
@@ -44,7 +48,6 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
44
 
45
  try:
46
  agent_instance = AgentArchitect()
47
-
48
  response = requests.get(questions_url, timeout=15)
49
  response.raise_for_status()
50
  questions_data = response.json()
@@ -55,9 +58,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
55
  for item in questions_data:
56
  task_id = item.get("task_id")
57
  question_text = item.get("question")
58
-
59
  submitted_answer = agent_instance(question_text)
60
-
61
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
62
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
63
 
 
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
 
5
  from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel, VisitWebpageTool
6
 
7
  # --- Constants ---
 
10
  # --- Agent Definition ---
11
  class AgentArchitect:
12
  def __init__(self):
13
+ # SECURE WAY: Fetch the token from the Space Secrets
14
+ # Make sure you have added 'HF_TOKEN' in your Space Settings!
15
+ hf_token = os.getenv("HF_TOKEN")
16
+
17
+ self.model = LiteLLMModel(
18
+ model_id="huggingface/Qwen/Qwen2.5-72B-Instruct",
19
+ api_key=hf_token
20
+ )
21
 
22
  self.tools = [DuckDuckGoSearchTool(), VisitWebpageTool()]
23
 
 
48
 
49
  try:
50
  agent_instance = AgentArchitect()
 
51
  response = requests.get(questions_url, timeout=15)
52
  response.raise_for_status()
53
  questions_data = response.json()
 
58
  for item in questions_data:
59
  task_id = item.get("task_id")
60
  question_text = item.get("question")
 
61
  submitted_answer = agent_instance(question_text)
 
62
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
63
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
64