magdap116 commited on
Commit
1a7ad09
·
verified ·
1 Parent(s): 2a02409

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -3
app.py CHANGED
@@ -53,7 +53,7 @@ def cache_answer(question: str, answer: str):
53
 
54
 
55
  # --- Model Setup ---
56
- MODEL_NAME = 'distilbert/distilgpt2'#'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B'#'mistralai/Mistral-7B-Instruct-v0.2'
57
 
58
  def load_model():
59
  """Download and load the model and tokenizer."""
@@ -87,8 +87,19 @@ class BasicAgent:
87
 
88
  def __call__(self, question: str) -> str:
89
  print(f"Agent received question (first 50 chars): {question[:50]}...")
90
-
91
- answer = self.agent.run(question)
 
 
 
 
 
 
 
 
 
 
 
92
  return answer
93
 
94
 
 
53
 
54
 
55
  # --- Model Setup ---
56
+ MODEL_NAME = 'EleutherAI/gpt-neo-2.7B'#'distilbert/distilgpt2'#'deepseek-ai/DeepSeek-R1-Distill-Qwen-7B'#'mistralai/Mistral-7B-Instruct-v0.2'
57
 
58
  def load_model():
59
  """Download and load the model and tokenizer."""
 
87
 
88
  def __call__(self, question: str) -> str:
89
  print(f"Agent received question (first 50 chars): {question[:50]}...")
90
+
91
+ encoded_input = tokenizer(question, return_tensors="pt", padding=True, truncation=True, max_length=512)
92
+
93
+ # Generate text using the model
94
+ output = model.generate(
95
+ encoded_input['input_ids'],
96
+ attention_mask=encoded_input['attention_mask'], # Pass attention mask
97
+ max_length=100,
98
+ pad_token_id=tokenizer.pad_token_id,
99
+
100
+ )
101
+
102
+ answer = tokenizer.decode(output[0], skip_special_tokens=True)
103
  return answer
104
 
105