magdap116 commited on
Commit
40d01b6
·
verified ·
1 Parent(s): 540fbbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -1
app.py CHANGED
@@ -28,7 +28,6 @@ model_math_tool = ModelMathTool()
28
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
29
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
30
 
31
- model = HfApiModel(model_id='mistralai/Mistral-7B-Instruct-v0.2', max_tokens=512)
32
 
33
 
34
 
@@ -53,11 +52,32 @@ def cache_answer(question: str, answer: str):
53
 
54
 
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  class BasicAgent:
57
  def __init__(self):
58
  print("BasicAgent initialized.")
59
  self.agent = CodeAgent(
60
  model=model,
 
61
  tools=[web_search,python_interpreter,visit_webpage_tool,model_math_tool],
62
  max_steps=1,
63
  verbosity_level=1,
 
28
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
29
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
30
 
 
31
 
32
 
33
 
 
52
 
53
 
54
 
55
+ # --- Model Setup ---
56
+ MODEL_NAME = 'mistralai/Mistral-7B-Instruct-v0.2'
57
+
58
+ def load_model():
59
+ """Download and load the model and tokenizer."""
60
+ try:
61
+ print(f"Loading model {MODEL_NAME}...")
62
+ model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
63
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
64
+ print(f"Model {MODEL_NAME} loaded successfully.")
65
+ return model, tokenizer
66
+ except Exception as e:
67
+ print(f"Error loading model: {e}")
68
+ raise
69
+
70
+ # Load the model and tokenizer locally
71
+ model, tokenizer = load_model()
72
+
73
+
74
+
75
  class BasicAgent:
76
  def __init__(self):
77
  print("BasicAgent initialized.")
78
  self.agent = CodeAgent(
79
  model=model,
80
+ tokenizer=tokenizer,
81
  tools=[web_search,python_interpreter,visit_webpage_tool,model_math_tool],
82
  max_steps=1,
83
  verbosity_level=1,