mohantest commited on
Commit
6541f2c
·
verified ·
1 Parent(s): a37efcb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -2,14 +2,12 @@ import logging
2
  import hashlib
3
  import json
4
  import os
5
- from smolagents import CodeAgent, tool
6
- from smolagents.models import HfApiModel # Correct import for HfApiModel
7
 
8
- # Set up logging
9
  logging.basicConfig(level=logging.INFO)
10
  logger = logging.getLogger(__name__)
11
 
12
- # Answer cache
13
  CACHE_FILE = "answer_cache.json"
14
  if os.path.exists(CACHE_FILE):
15
  with open(CACHE_FILE) as f:
@@ -21,7 +19,6 @@ def save_cache():
21
  with open(CACHE_FILE, "w") as f:
22
  json.dump(answer_cache, f)
23
 
24
- # ---------- Tools ----------
25
  @tool
26
  def calculator(expression: str) -> str:
27
  """
@@ -69,11 +66,10 @@ def web_search(query: str) -> str:
69
  except Exception as e:
70
  return f"Search error: {e}"
71
 
72
- # ---------- Agent ----------
73
- # Use HfApiModel with a specific model ID (you can change this)
74
- model = HfApiModel(model_id="HuggingFaceH4/zephyr-7b-beta") # or any other model
75
 
76
- # Only include web_search if the package is installed
77
  tools = [calculator]
78
  try:
79
  import duckduckgo_search
@@ -84,9 +80,8 @@ except ImportError:
84
 
85
  agent = CodeAgent(tools=tools, model=model)
86
 
87
- # ---------- Main entry point ----------
88
  def answer_question(question: str) -> str:
89
- """Called by the evaluator for each question."""
90
  q_hash = hashlib.md5(question.encode()).hexdigest()
91
  if q_hash in answer_cache:
92
  logger.info(f"Cache hit for question: {question[:50]}...")
 
2
  import hashlib
3
  import json
4
  import os
5
+ from smolagents import CodeAgent, HfApiModel, tool
 
6
 
 
7
  logging.basicConfig(level=logging.INFO)
8
  logger = logging.getLogger(__name__)
9
 
10
+ # Cache for answers
11
  CACHE_FILE = "answer_cache.json"
12
  if os.path.exists(CACHE_FILE):
13
  with open(CACHE_FILE) as f:
 
19
  with open(CACHE_FILE, "w") as f:
20
  json.dump(answer_cache, f)
21
 
 
22
  @tool
23
  def calculator(expression: str) -> str:
24
  """
 
66
  except Exception as e:
67
  return f"Search error: {e}"
68
 
69
+ # Initialize the model (you can change the model ID)
70
+ model = HfApiModel(model_id="HuggingFaceH4/zephyr-7b-beta")
 
71
 
72
+ # Assemble tools (web_search only if duckduckgo-search is installed)
73
  tools = [calculator]
74
  try:
75
  import duckduckgo_search
 
80
 
81
  agent = CodeAgent(tools=tools, model=model)
82
 
 
83
  def answer_question(question: str) -> str:
84
+ """Main entry point for the evaluator."""
85
  q_hash = hashlib.md5(question.encode()).hexdigest()
86
  if q_hash in answer_cache:
87
  logger.info(f"Cache hit for question: {question[:50]}...")