Spaces:
Configuration error
Configuration error
EcoFriendlyWoodVerneer commited on
Commit Β·
9ce5e4a
1
Parent(s): 5e1f034
Pls work v3
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 58 |
num_beams=4,
|
| 59 |
-
|
| 60 |
)
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
| 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"
|