Spaces:
Running
Running
Commit
·
7e40c67
1
Parent(s):
fc37b5b
progress spinner attempt
Browse files
app.py
CHANGED
@@ -8,7 +8,8 @@ import matplotlib.pyplot as plt
|
|
8 |
from pymystem3 import Mystem
|
9 |
import io
|
10 |
from rapidfuzz import fuzz
|
11 |
-
from tqdm import tqdm
|
|
|
12 |
import torch
|
13 |
|
14 |
# Initialize pymystem3 for lemmatization
|
@@ -43,39 +44,26 @@ 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 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
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
|
76 |
translated_text = translation_tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
77 |
return translated_text
|
78 |
|
|
|
|
|
79 |
# Function for VADER sentiment analysis with label mapping
|
80 |
def get_vader_sentiment(text):
|
81 |
score = vader_analyzer.polarity_scores(text)["compound"]
|
|
|
8 |
from pymystem3 import Mystem
|
9 |
import io
|
10 |
from rapidfuzz import fuzz
|
11 |
+
from tqdm.auto import tqdm
|
12 |
+
import time
|
13 |
import torch
|
14 |
|
15 |
# Initialize pymystem3 for lemmatization
|
|
|
44 |
# Get the number of tokens in the input
|
45 |
input_length = inputs.input_ids.shape[1]
|
46 |
|
47 |
+
# Set up a simple spinner
|
48 |
+
with tqdm(total=0, bar_format='{desc}', desc="Translating...") as pbar:
|
49 |
+
# Generate translation
|
50 |
+
translated_tokens = translation_model.generate(
|
51 |
+
**inputs,
|
52 |
+
num_beams=5,
|
53 |
+
max_length=input_length * 2, # Adjust as needed
|
54 |
+
no_repeat_ngram_size=2,
|
55 |
+
early_stopping=True
|
56 |
+
)
|
57 |
+
|
58 |
+
# Update the spinner description to show completion
|
59 |
+
pbar.set_description_str("Translation completed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# Decode the translated tokens
|
62 |
translated_text = translation_tokenizer.batch_decode(translated_tokens, skip_special_tokens=True)[0]
|
63 |
return translated_text
|
64 |
|
65 |
+
|
66 |
+
|
67 |
# Function for VADER sentiment analysis with label mapping
|
68 |
def get_vader_sentiment(text):
|
69 |
score = vader_analyzer.polarity_scores(text)["compound"]
|