HemanM commited on
Commit
14bd5d8
ยท
verified ยท
1 Parent(s): c62b1b6

Update inference.py

Browse files
Files changed (1) hide show
  1. inference.py +20 -10
inference.py CHANGED
@@ -18,7 +18,7 @@ tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
18
  model = None
19
  last_mod_time = 0
20
 
21
- # ๐Ÿ” Load Evo model
22
  def load_model():
23
  global model, last_mod_time
24
  try:
@@ -34,14 +34,14 @@ def load_model():
34
  model = None
35
  return model
36
 
37
- # ๐Ÿ”ฎ Evo inference
38
  def evo_infer(query, options, user_context=""):
39
  model = load_model()
40
  if model is None:
41
  return "Model Error", 0.0, "Model not available", ""
42
 
43
- context_str = "\n".join(web_search(query) + ([user_context] if user_context else []))
44
- input_pairs = [f"{query} [SEP] {opt} [CTX] {context_str}" for opt in options]
45
 
46
  scores = []
47
  for pair in input_pairs:
@@ -56,10 +56,10 @@ def evo_infer(query, options, user_context=""):
56
  options[best_idx],
57
  max(scores),
58
  f"{options[0]}: {scores[0]:.3f} vs {options[1]}: {scores[1]:.3f}",
59
- context_str
60
  )
61
 
62
- # ๐Ÿ’ฌ GPT fallback (renamed properly to fix import)
63
  def get_gpt_response(query, user_context=""):
64
  try:
65
  context_block = f"\n\nContext:\n{user_context}" if user_context else ""
@@ -72,9 +72,19 @@ def get_gpt_response(query, user_context=""):
72
  except Exception as e:
73
  return f"โš ๏ธ GPT error:\n{str(e)}"
74
 
75
- # ๐Ÿ”„ UI integration
76
  def evo_chat_predict(history, query, options):
77
- context = "\n".join(history[-6:]) if history else ""
 
 
 
 
 
 
 
 
 
 
78
  evo_ans, evo_score, evo_reason, evo_ctx = evo_infer(query, options, context)
79
  return {
80
  "answer": evo_ans,
@@ -83,7 +93,7 @@ def evo_chat_predict(history, query, options):
83
  "context_used": evo_ctx
84
  }
85
 
86
- # ๐Ÿ“Š Evo config
87
  def get_model_config():
88
  return {
89
  "num_layers": 6,
@@ -94,7 +104,7 @@ def get_model_config():
94
  "accuracy": "~64.5%"
95
  }
96
 
97
- # ๐Ÿ’ป System info
98
  def get_system_stats():
99
  gpu_info = torch.cuda.get_device_properties(0) if torch.cuda.is_available() else None
100
  memory = psutil.virtual_memory()
 
18
  model = None
19
  last_mod_time = 0
20
 
21
+ # ๐Ÿ” Load Evo model with auto-reload
22
  def load_model():
23
  global model, last_mod_time
24
  try:
 
34
  model = None
35
  return model
36
 
37
+ # ๐Ÿ”ฎ Evo inference core logic
38
  def evo_infer(query, options, user_context=""):
39
  model = load_model()
40
  if model is None:
41
  return "Model Error", 0.0, "Model not available", ""
42
 
43
+ context_text = "\n".join(web_search(query) + ([user_context] if user_context else []))
44
+ input_pairs = [f"{query} [SEP] {opt} [CTX] {context_text}" for opt in options]
45
 
46
  scores = []
47
  for pair in input_pairs:
 
56
  options[best_idx],
57
  max(scores),
58
  f"{options[0]}: {scores[0]:.3f} vs {options[1]}: {scores[1]:.3f}",
59
+ context_text
60
  )
61
 
62
+ # ๐Ÿ’ฌ GPT fallback (used for comparison only)
63
  def get_gpt_response(query, user_context=""):
64
  try:
65
  context_block = f"\n\nContext:\n{user_context}" if user_context else ""
 
72
  except Exception as e:
73
  return f"โš ๏ธ GPT error:\n{str(e)}"
74
 
75
+ # ๐Ÿค– Evo live chat prediction
76
  def evo_chat_predict(history, query, options):
77
+ try:
78
+ # Support list or DataFrame
79
+ if isinstance(history, list):
80
+ context = "\n".join(history[-6:])
81
+ elif hasattr(history, "empty") and not history.empty:
82
+ context = "\n".join(history.tail(6).astype(str).tolist())
83
+ else:
84
+ context = ""
85
+ except Exception:
86
+ context = ""
87
+
88
  evo_ans, evo_score, evo_reason, evo_ctx = evo_infer(query, options, context)
89
  return {
90
  "answer": evo_ans,
 
93
  "context_used": evo_ctx
94
  }
95
 
96
+ # ๐Ÿ“Š Evo architecture stats
97
  def get_model_config():
98
  return {
99
  "num_layers": 6,
 
104
  "accuracy": "~64.5%"
105
  }
106
 
107
+ # ๐Ÿ–ฅ๏ธ System runtime stats
108
  def get_system_stats():
109
  gpu_info = torch.cuda.get_device_properties(0) if torch.cuda.is_available() else None
110
  memory = psutil.virtual_memory()