ErdemTheFixer commited on
Commit
b81bc86
·
verified ·
1 Parent(s): 4ea8017

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -3,36 +3,37 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
6
- from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, WikipediaSearchTool, HfApiModel
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
 
12
  # --- Basic Agent Definition ---
13
-
14
  class BasicAgent:
15
  def __init__(self):
16
  print("BasicAgent initialized.")
17
 
18
- # Use Hugging Face Inference API instead of OpenAI
19
- model = HfApiModel(model_id="meta-llama/Meta-Llama-3-8B-Instruct") #meta-llama/Llama-3.1-8B-Instruct
 
 
20
 
21
  # Tools
22
  duckduckgo = DuckDuckGoSearchTool()
23
  wikipedia = WikipediaSearchTool()
24
 
25
- # Agent
26
  self.agent = CodeAgent(
27
- model=model,
28
  tools=[duckduckgo, wikipedia]
29
  )
30
 
31
  def __call__(self, question: str) -> str:
32
  print(f"Agent received question (first 50 chars): {question[:50]}...")
33
- fixed_answer = self.agent.run(question)
34
- print(f"Agent returning fixed answer: {fixed_answer}")
35
- return fixed_answer
36
 
37
 
38
 
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, WikipediaSearchTool, InferenceClientModel
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
 
12
  # --- Basic Agent Definition ---
 
13
  class BasicAgent:
14
  def __init__(self):
15
  print("BasicAgent initialized.")
16
 
17
+ # Load the HF-supported model using InferenceClientModel
18
+ self.model = InferenceClientModel(
19
+ model_id="meta-llama/Meta-Llama-3-8B-Instruct" #meta-llama/Llama-3.1-8B-Instruct
20
+ )
21
 
22
  # Tools
23
  duckduckgo = DuckDuckGoSearchTool()
24
  wikipedia = WikipediaSearchTool()
25
 
26
+ # Compose the agent
27
  self.agent = CodeAgent(
28
+ model=self.model,
29
  tools=[duckduckgo, wikipedia]
30
  )
31
 
32
  def __call__(self, question: str) -> str:
33
  print(f"Agent received question (first 50 chars): {question[:50]}...")
34
+ answer = self.agent.run(question)
35
+ print(f"Agent returning answer: {answer[:80]}...")
36
+ return answer
37
 
38
 
39