Spaces:
Sleeping
Sleeping
refresh text box in gradio
Browse files
app.py
CHANGED
@@ -77,7 +77,8 @@ def run_full_evaluation_gradio():
|
|
77 |
return
|
78 |
|
79 |
try:
|
80 |
-
|
|
|
81 |
|
82 |
device = sentiment_inferer.device
|
83 |
model = sentiment_inferer.model
|
@@ -87,7 +88,8 @@ def run_full_evaluation_gradio():
|
|
87 |
|
88 |
yield "Loading IMDB test dataset (this might take a moment)..."
|
89 |
imdb_test_full = load_dataset("imdb", split="test")
|
90 |
-
|
|
|
91 |
|
92 |
def tokenize_function(examples):
|
93 |
tokenized_output = tokenizer(examples["text"], truncation=True, padding="max_length", max_length=max_length)
|
@@ -100,11 +102,11 @@ def run_full_evaluation_gradio():
|
|
100 |
tokenized_imdb_test_full.set_format("torch", columns=["input_ids", "attention_mask", "labels", "lengths"])
|
101 |
|
102 |
test_dataloader_full = DataLoader(tokenized_imdb_test_full, batch_size=batch_size)
|
103 |
-
|
|
|
104 |
|
105 |
# The 'evaluate' function from evaluation.py is now a generator.
|
106 |
-
# Iterate through its yielded updates and results.
|
107 |
-
final_results_str = ""
|
108 |
for update in evaluate(model, test_dataloader_full, device):
|
109 |
if isinstance(update, dict):
|
110 |
# This is the final results dictionary
|
@@ -115,16 +117,13 @@ def run_full_evaluation_gradio():
|
|
115 |
else:
|
116 |
results_str += f"{key.capitalize()}: {value}\n"
|
117 |
results_str += "\nEvaluation finished."
|
118 |
-
|
119 |
-
yield
|
120 |
break # Stop after getting the results dict
|
121 |
else:
|
122 |
# This is a progress string
|
123 |
-
|
124 |
-
|
125 |
-
# Ensure the final formatted results string is yielded if not already (e.g., if loop broke early)
|
126 |
-
# However, the logic above should yield it before breaking.
|
127 |
-
# If evaluate could end without yielding a dict, this might be needed.
|
128 |
|
129 |
except Exception as e:
|
130 |
import traceback
|
|
|
77 |
return
|
78 |
|
79 |
try:
|
80 |
+
accumulated_text = "Starting full evaluation... This will process 25,000 samples and may take 10-20 minutes. Please be patient.\n"
|
81 |
+
yield accumulated_text
|
82 |
|
83 |
device = sentiment_inferer.device
|
84 |
model = sentiment_inferer.model
|
|
|
88 |
|
89 |
yield "Loading IMDB test dataset (this might take a moment)..."
|
90 |
imdb_test_full = load_dataset("imdb", split="test")
|
91 |
+
accumulated_text += f"IMDB test dataset loaded ({len(imdb_test_full)} samples). Tokenizing dataset...\n"
|
92 |
+
yield accumulated_text
|
93 |
|
94 |
def tokenize_function(examples):
|
95 |
tokenized_output = tokenizer(examples["text"], truncation=True, padding="max_length", max_length=max_length)
|
|
|
102 |
tokenized_imdb_test_full.set_format("torch", columns=["input_ids", "attention_mask", "labels", "lengths"])
|
103 |
|
104 |
test_dataloader_full = DataLoader(tokenized_imdb_test_full, batch_size=batch_size)
|
105 |
+
accumulated_text += "Dataset tokenized and DataLoader prepared. Starting model evaluation on the test set...\n"
|
106 |
+
yield accumulated_text
|
107 |
|
108 |
# The 'evaluate' function from evaluation.py is now a generator.
|
109 |
+
# Iterate through its yielded updates and results, accumulating text.
|
|
|
110 |
for update in evaluate(model, test_dataloader_full, device):
|
111 |
if isinstance(update, dict):
|
112 |
# This is the final results dictionary
|
|
|
117 |
else:
|
118 |
results_str += f"{key.capitalize()}: {value}\n"
|
119 |
results_str += "\nEvaluation finished."
|
120 |
+
accumulated_text += results_str
|
121 |
+
yield accumulated_text
|
122 |
break # Stop after getting the results dict
|
123 |
else:
|
124 |
# This is a progress string
|
125 |
+
accumulated_text += str(update) + "\n" # Append newline to each progress string
|
126 |
+
yield accumulated_text
|
|
|
|
|
|
|
127 |
|
128 |
except Exception as e:
|
129 |
import traceback
|