wt002 commited on
Commit
01bade2
·
verified ·
1 Parent(s): 202ae29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -18
app.py CHANGED
@@ -9,7 +9,7 @@ import wikipediaapi
9
  import pandas as pd
10
  from transformers import pipeline # or HfAgent if you want the higher-level agent
11
  from huggingface_hub import InferenceClient # Updated import
12
- from huggingface_hub.inference._text_generation import TextGenerationResponse
13
 
14
  load_dotenv()
15
 
@@ -21,33 +21,27 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
21
  # --- Basic Agent Definition ---
22
 
23
  class BasicAgent:
24
- def __init__(self, searx_url: str = "https://search.example.org"):
25
- # Initialize HF Inference Client
26
- self.client = InferenceClient(model="bigcode/starcoder")
27
  self.searx_url = searx_url
28
- print("BasicAgent initialized with Inference API")
29
 
30
  def __call__(self, question: str) -> str:
31
- print(f"Question: {question[:50]}...")
32
- response: TextGenerationResponse = self.client.text_generation(
33
  prompt=question,
34
- max_new_tokens=100
 
35
  )
36
- return response
37
 
38
  def web_search(self, query: str) -> List[Dict]:
39
- """Use SearxNG meta-search engine"""
40
- params = {
41
- "q": query,
42
- "format": "json",
43
- "engines": "google,bing,duckduckgo"
44
- }
45
  try:
46
  response = requests.get(self.searx_url, params=params, timeout=10)
47
- response.raise_for_status()
48
  return response.json().get("results", [])
49
- except requests.RequestException as e:
50
- print(f"Search error: {str(e)}")
51
  return []
52
 
53
  def wikipedia_search(self, query: str) -> str:
 
9
  import pandas as pd
10
  from transformers import pipeline # or HfAgent if you want the higher-level agent
11
  from huggingface_hub import InferenceClient # Updated import
12
+
13
 
14
  load_dotenv()
15
 
 
21
  # --- Basic Agent Definition ---
22
 
23
  class BasicAgent:
24
+ def __init__(self, model: str = "google/gemma-7b", searx_url: str = "https://search.example.org"):
25
+ self.client = InferenceClient(model=model)
 
26
  self.searx_url = searx_url
27
+ print(f"Initialized with model: {model}")
28
 
29
  def __call__(self, question: str) -> str:
30
+ print(f"Processing: {question[:50]}...")
31
+ return self.client.text_generation(
32
  prompt=question,
33
+ max_new_tokens=100,
34
+ temperature=0.7
35
  )
 
36
 
37
  def web_search(self, query: str) -> List[Dict]:
38
+ """Search using SearxNG"""
39
+ params = {"q": query, "format": "json", "engines": "google,bing"}
 
 
 
 
40
  try:
41
  response = requests.get(self.searx_url, params=params, timeout=10)
 
42
  return response.json().get("results", [])
43
+ except Exception as e:
44
+ print(f"Search failed: {e}")
45
  return []
46
 
47
  def wikipedia_search(self, query: str) -> str: