Spaces:
Running
Running
Commit
·
fc37b5b
1
Parent(s):
f6e9269
russification and optimization continued errors correction
Browse files
app.py
CHANGED
@@ -43,22 +43,33 @@ def translate(text):
|
|
43 |
# Get the number of tokens in the input
|
44 |
input_length = inputs.input_ids.shape[1]
|
45 |
|
46 |
-
#
|
47 |
-
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
progress_bar.update(1)
|
52 |
|
53 |
-
# Generate translation
|
|
|
54 |
translated_tokens = translation_model.generate(
|
55 |
**inputs,
|
56 |
num_beams=5,
|
57 |
-
max_length=
|
58 |
-
|
|
|
59 |
)
|
60 |
|
61 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
progress_bar.close()
|
63 |
|
64 |
# Decode the translated tokens
|
|
|
43 |
# Get the number of tokens in the input
|
44 |
input_length = inputs.input_ids.shape[1]
|
45 |
|
46 |
+
# Estimate the maximum length of the output
|
47 |
+
max_length = input_length * 2 # This is an estimate, adjust as needed
|
48 |
|
49 |
+
# Set up the progress bar
|
50 |
+
progress_bar = tqdm(total=100, desc="Translating", unit="%")
|
|
|
51 |
|
52 |
+
# Generate translation
|
53 |
+
start_time = time.time()
|
54 |
translated_tokens = translation_model.generate(
|
55 |
**inputs,
|
56 |
num_beams=5,
|
57 |
+
max_length=max_length,
|
58 |
+
no_repeat_ngram_size=2,
|
59 |
+
early_stopping=True
|
60 |
)
|
61 |
|
62 |
+
# Estimate progress based on time
|
63 |
+
while not translated_tokens.size(1):
|
64 |
+
elapsed_time = time.time() - start_time
|
65 |
+
estimated_progress = min(int((elapsed_time / (input_length * 0.1)) * 100), 99)
|
66 |
+
progress_bar.n = estimated_progress
|
67 |
+
progress_bar.refresh()
|
68 |
+
time.sleep(0.1)
|
69 |
+
|
70 |
+
# Ensure the progress bar reaches 100%
|
71 |
+
progress_bar.n = 100
|
72 |
+
progress_bar.refresh()
|
73 |
progress_bar.close()
|
74 |
|
75 |
# Decode the translated tokens
|