AItool commited on
Commit
5e99c79
·
verified ·
1 Parent(s): 83fdf47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -10
app.py CHANGED
@@ -141,9 +141,6 @@ def build_messages(user_text, profile, blocks):
141
  {"role": "user", "content": user_text}
142
  ]
143
 
144
- # ----------------------------
145
- # Generate
146
- # ----------------------------
147
  def chat(user_text, model_label, blocks_json):
148
  data = load_blocks()
149
  blocks = parse_blocks_editor(blocks_json, data.get("language_blocks", []))
@@ -153,14 +150,14 @@ def chat(user_text, model_label, blocks_json):
153
 
154
  messages = build_messages(user_text, data["user_profile"], blocks)
155
 
156
- inputs = tokenizer.apply_chat_template(
157
- messages,
158
- add_generation_prompt=True,
159
- tokenize=True,
160
- return_tensors="pt",
161
- return_dict=True # <-- this makes inputs a dict
162
  ).to("cpu")
163
-
164
  start = time.time()
165
  with torch.no_grad():
166
  outputs = model.generate(
@@ -182,6 +179,7 @@ def chat(user_text, model_label, blocks_json):
182
 
183
  return gen_text, metrics
184
 
 
185
  def parse_blocks_editor(text, fallback):
186
  if not text or not text.strip():
187
  return fallback
 
141
  {"role": "user", "content": user_text}
142
  ]
143
 
 
 
 
144
  def chat(user_text, model_label, blocks_json):
145
  data = load_blocks()
146
  blocks = parse_blocks_editor(blocks_json, data.get("language_blocks", []))
 
150
 
151
  messages = build_messages(user_text, data["user_profile"], blocks)
152
 
153
+ inputs = tokenizer.apply_chat_template(
154
+ messages,
155
+ add_generation_prompt=True,
156
+ tokenize=True,
157
+ return_tensors="pt",
158
+ return_dict=True # ensures inputs is a dict, not just a tensor
159
  ).to("cpu")
160
+
161
  start = time.time()
162
  with torch.no_grad():
163
  outputs = model.generate(
 
179
 
180
  return gen_text, metrics
181
 
182
+
183
  def parse_blocks_editor(text, fallback):
184
  if not text or not text.strip():
185
  return fallback