Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,36 +21,40 @@ def simulate_training(epochs, learning_rate):
|
|
| 21 |
accuracies = []
|
| 22 |
logs = []
|
| 23 |
|
| 24 |
-
#
|
| 25 |
current_acc = 0.55 + random.uniform(0, 0.05)
|
| 26 |
|
| 27 |
for epoch in range(epochs):
|
| 28 |
time.sleep(0.3)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
improvement = learning_rate * random.uniform(
|
| 32 |
current_acc += improvement
|
| 33 |
|
| 34 |
-
# plateau effect
|
| 35 |
if epoch > epochs * 0.6:
|
| 36 |
-
current_acc += random.uniform(-0.
|
| 37 |
|
| 38 |
-
|
|
|
|
| 39 |
accuracies.append(round(current_acc, 3))
|
| 40 |
logs.append(f"Epoch {epoch+1}: Validation Accuracy = {current_acc:.3f}")
|
| 41 |
|
| 42 |
-
#
|
| 43 |
plt.figure(figsize=(4, 2))
|
| 44 |
plt.plot(range(1, epochs + 1), accuracies, marker="o", color="tab:blue")
|
|
|
|
| 45 |
plt.title("Simulated Validation Accuracy per Epoch")
|
| 46 |
plt.xlabel("Epoch")
|
| 47 |
plt.ylabel("Accuracy")
|
| 48 |
plt.ylim(0.5, 1.0)
|
| 49 |
plt.grid(True)
|
|
|
|
| 50 |
|
| 51 |
final_acc = round(accuracies[-1], 3)
|
| 52 |
return plt, "\n".join(logs), final_acc
|
| 53 |
|
|
|
|
| 54 |
# -------- Real Inference Function --------
|
| 55 |
def analyze_text(text):
|
| 56 |
if not sentiment_analyzer:
|
|
|
|
| 21 |
accuracies = []
|
| 22 |
logs = []
|
| 23 |
|
| 24 |
+
# Start lower for visible climb
|
| 25 |
current_acc = 0.55 + random.uniform(0, 0.05)
|
| 26 |
|
| 27 |
for epoch in range(epochs):
|
| 28 |
time.sleep(0.3)
|
| 29 |
|
| 30 |
+
# Improvement scaled for realistic visible growth
|
| 31 |
+
improvement = learning_rate * random.uniform(20, 80)
|
| 32 |
current_acc += improvement
|
| 33 |
|
| 34 |
+
# Add small random noise and plateau effect
|
| 35 |
if epoch > epochs * 0.6:
|
| 36 |
+
current_acc += random.uniform(-0.015, 0.005)
|
| 37 |
|
| 38 |
+
# Clamp values between 0.55 and 0.95
|
| 39 |
+
current_acc = max(min(current_acc, 0.95), 0.55)
|
| 40 |
accuracies.append(round(current_acc, 3))
|
| 41 |
logs.append(f"Epoch {epoch+1}: Validation Accuracy = {current_acc:.3f}")
|
| 42 |
|
| 43 |
+
# Create the chart
|
| 44 |
plt.figure(figsize=(4, 2))
|
| 45 |
plt.plot(range(1, epochs + 1), accuracies, marker="o", color="tab:blue")
|
| 46 |
+
plt.axhline(y=accuracies[0], color="gray", linestyle="--", linewidth=1, label="Starting accuracy")
|
| 47 |
plt.title("Simulated Validation Accuracy per Epoch")
|
| 48 |
plt.xlabel("Epoch")
|
| 49 |
plt.ylabel("Accuracy")
|
| 50 |
plt.ylim(0.5, 1.0)
|
| 51 |
plt.grid(True)
|
| 52 |
+
plt.legend()
|
| 53 |
|
| 54 |
final_acc = round(accuracies[-1], 3)
|
| 55 |
return plt, "\n".join(logs), final_acc
|
| 56 |
|
| 57 |
+
|
| 58 |
# -------- Real Inference Function --------
|
| 59 |
def analyze_text(text):
|
| 60 |
if not sentiment_analyzer:
|