EcoFriendlyWoodVerneer commited on
Commit
9ce5e4a
Β·
1 Parent(s): 5e1f034

Pls work v3

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -47,18 +47,24 @@ def translate_text(text: str):
47
  return "[Model not ready yet β€” upload/checkpoint missing.]"
48
 
49
  tok, model = get_model()
50
- inputs = tok(text, return_tensors="pt", truncation=True, max_length=128)
 
 
 
51
  if torch.cuda.is_available():
52
  inputs = {k: v.to("cuda") for k, v in inputs.items()}
53
 
54
  with torch.no_grad():
55
  out_ids = model.generate(
56
  **inputs,
57
- max_new_tokens=128,
58
  num_beams=4,
59
- length_penalty=1.0,
60
  )
61
- return tok.decode(out_ids[0], skip_special_tokens=True)
 
 
 
62
 
63
  title = "EN β†’ ZH Translator"
64
  status = "βœ… Model ready" if model_ready() else "⏳ Model not ready"
 
47
  return "[Model not ready yet β€” upload/checkpoint missing.]"
48
 
49
  tok, model = get_model()
50
+
51
+ prompt = "translate English to Chinese: " + text # βœ… key fix
52
+
53
+ inputs = tok(prompt, return_tensors="pt", truncation=True, max_length=256)
54
  if torch.cuda.is_available():
55
  inputs = {k: v.to("cuda") for k, v in inputs.items()}
56
 
57
  with torch.no_grad():
58
  out_ids = model.generate(
59
  **inputs,
60
+ max_new_tokens=80,
61
  num_beams=4,
62
+ early_stopping=True,
63
  )
64
+
65
+ result = tok.decode(out_ids[0], skip_special_tokens=True).strip()
66
+ return result if result else "[No output β€” check prompt prefix / checkpoint quality]"
67
+
68
 
69
  title = "EN β†’ ZH Translator"
70
  status = "βœ… Model ready" if model_ready() else "⏳ Model not ready"