Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,7 @@ import os
|
|
| 3 |
import datetime
|
| 4 |
import json
|
| 5 |
import tempfile
|
| 6 |
-
import
|
| 7 |
-
import io
|
| 8 |
-
import base64
|
| 9 |
|
| 10 |
|
| 11 |
# === Import Groq API ===
|
|
@@ -172,17 +170,65 @@ def save_plot_to_base64():
|
|
| 172 |
return "data:image/png;base64," + encoded
|
| 173 |
|
| 174 |
|
| 175 |
-
#
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
| 183 |
|
| 184 |
-
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
|
| 188 |
# === Gradio Interface ===
|
|
@@ -211,8 +257,14 @@ with gr.Blocks() as demo:
|
|
| 211 |
refresh_btn = gr.Button("Refresh History")
|
| 212 |
refresh_btn.click(get_history, outputs=history_box)
|
| 213 |
|
|
|
|
|
|
|
| 214 |
with gr.Tab("Progress π"):
|
| 215 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
|
| 218 |
# === Launch ===
|
|
|
|
| 3 |
import datetime
|
| 4 |
import json
|
| 5 |
import tempfile
|
| 6 |
+
import datetime
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
# === Import Groq API ===
|
|
|
|
| 170 |
return "data:image/png;base64," + encoded
|
| 171 |
|
| 172 |
|
| 173 |
+
# === Daily Tracking ===
|
| 174 |
+
DAILY_STATS = {
|
| 175 |
+
"date": str(datetime.date.today()),
|
| 176 |
+
"attempts": 0,
|
| 177 |
+
"correct": 0,
|
| 178 |
+
"errors": 0,
|
| 179 |
+
"current_streak": 0,
|
| 180 |
+
"badge": None
|
| 181 |
+
}
|
| 182 |
|
| 183 |
+
def update_daily_stats(is_correct: bool):
|
| 184 |
+
"""Update stats after each attempt."""
|
| 185 |
+
today = str(datetime.date.today())
|
| 186 |
+
|
| 187 |
+
# reset if date changes
|
| 188 |
+
if DAILY_STATS["date"] != today:
|
| 189 |
+
DAILY_STATS.update({
|
| 190 |
+
"date": today,
|
| 191 |
+
"attempts": 0,
|
| 192 |
+
"correct": 0,
|
| 193 |
+
"errors": 0,
|
| 194 |
+
"current_streak": 0,
|
| 195 |
+
"badge": None
|
| 196 |
+
})
|
| 197 |
+
|
| 198 |
+
DAILY_STATS["attempts"] += 1
|
| 199 |
+
|
| 200 |
+
if is_correct:
|
| 201 |
+
DAILY_STATS["correct"] += 1
|
| 202 |
+
DAILY_STATS["current_streak"] += 1
|
| 203 |
+
if DAILY_STATS["current_streak"] >= 5:
|
| 204 |
+
DAILY_STATS["badge"] = "π
5-in-a-row Streak!"
|
| 205 |
+
else:
|
| 206 |
+
DAILY_STATS["errors"] += 1
|
| 207 |
+
DAILY_STATS["current_streak"] = 0 # reset streak
|
| 208 |
+
|
| 209 |
+
return get_progress_summary()
|
| 210 |
+
|
| 211 |
+
def get_progress_summary():
|
| 212 |
+
"""Return formatted progress text + badge."""
|
| 213 |
+
text = (
|
| 214 |
+
f"π
Date: {DAILY_STATS['date']}\n"
|
| 215 |
+
f"π’ Attempts: {DAILY_STATS['attempts']}\n"
|
| 216 |
+
f"β
Correct: {DAILY_STATS['correct']}\n"
|
| 217 |
+
f"β Errors: {DAILY_STATS['errors']}\n"
|
| 218 |
+
f"π₯ Streak: {DAILY_STATS['current_streak']}\n"
|
| 219 |
+
)
|
| 220 |
+
if DAILY_STATS["badge"]:
|
| 221 |
+
text += f"\nπ Badge Earned: {DAILY_STATS['badge']}"
|
| 222 |
+
return text
|
| 223 |
+
|
| 224 |
+
# === Inside Gradio UI ===
|
| 225 |
+
with gr.Tab("Progress π"):
|
| 226 |
+
gr.Markdown("### π Your Daily Progress")
|
| 227 |
+
progress_box = gr.Textbox(label="Todayβs Stats", interactive=False, lines=8)
|
| 228 |
+
|
| 229 |
+
# Refresh button
|
| 230 |
+
refresh_progress = gr.Button("π Refresh Progress")
|
| 231 |
+
refresh_progress.click(get_progress_summary, outputs=progress_box)
|
| 232 |
|
| 233 |
|
| 234 |
# === Gradio Interface ===
|
|
|
|
| 257 |
refresh_btn = gr.Button("Refresh History")
|
| 258 |
refresh_btn.click(get_history, outputs=history_box)
|
| 259 |
|
| 260 |
+
# with gr.Tab("Progress π"):
|
| 261 |
+
# gr.Markdown("Error tracking & progress visualization coming soon!")
|
| 262 |
with gr.Tab("Progress π"):
|
| 263 |
+
gr.Markdown("### π Your Daily Progress")
|
| 264 |
+
progress_box = gr.Textbox(label="Todayβs Stats", interactive=False, lines=8)
|
| 265 |
+
|
| 266 |
+
refresh_progress = gr.Button("π Refresh Progress")
|
| 267 |
+
refresh_progress.click(get_progress_summary, outputs=progress_box)
|
| 268 |
|
| 269 |
|
| 270 |
# === Launch ===
|