Emeritus-21 commited on
Commit
d11f062
·
verified ·
1 Parent(s): f3b428e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -1,4 +1,5 @@
1
  # app.py — HTR Space with Feedback Loop, Memory Post-Correction, and GRPO Export
 
2
  import os, time, json, hashlib, difflib, uuid, csv
3
  from datetime import datetime
4
  from collections import Counter, defaultdict
@@ -71,9 +72,10 @@ def _build_inputs(processor, tokenizer, image: Image.Image, prompt: str):
71
 
72
  if tokenizer and hasattr(tokenizer, "apply_chat_template"):
73
  chat_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
74
- return processor(text=[chat_prompt], images=[image], return_tensors="pt")
 
75
 
76
- return processor(text=[prompt], images=[image], return_tensors="pt")
77
 
78
 
79
  def _decode_text(model, processor, tokenizer, output_ids, prompt: str):
@@ -142,8 +144,9 @@ def _apply_memory(text: str, model_choice: str, enabled: bool):
142
  text = text.replace(wrong, right)
143
  # 2) Global replacements
144
  for wrong, right in rules.get("global", {}).items():
145
- if wrong and right:
146
- text = text.replace(wrong, right)
 
147
  return text
148
 
149
  def _compile_rules_from_feedback(min_count: int = 2, max_phrase_len: int = 40):
@@ -608,4 +611,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
608
 
609
  # The `if __name__ == "__main__":` block should be at the top level
610
  if __name__ == "__main__":
611
- demo.queue(max_size=50).launch(share=True)
 
1
  # app.py — HTR Space with Feedback Loop, Memory Post-Correction, and GRPO Export
2
+
3
  import os, time, json, hashlib, difflib, uuid, csv
4
  from datetime import datetime
5
  from collections import Counter, defaultdict
 
72
 
73
  if tokenizer and hasattr(tokenizer, "apply_chat_template"):
74
  chat_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
75
+ # Explicitly set truncation=False to prevent the token mismatch error
76
+ return processor(text=[chat_prompt], images=[image], return_tensors="pt", truncation=False)
77
 
78
+ return processor(text=[prompt], images=[image], return_tensors="pt", truncation=False)
79
 
80
 
81
  def _decode_text(model, processor, tokenizer, output_ids, prompt: str):
 
144
  text = text.replace(wrong, right)
145
  # 2) Global replacements
146
  for wrong, right in rules.get("global", {}).items():
147
+ for wrong, right in rules.get("global", {}).items():
148
+ if wrong and right:
149
+ text = text.replace(wrong, right)
150
  return text
151
 
152
  def _compile_rules_from_feedback(min_count: int = 2, max_phrase_len: int = 40):
 
611
 
612
  # The `if __name__ == "__main__":` block should be at the top level
613
  if __name__ == "__main__":
614
+ demo.queue(max_size=50).launch(share=True)