lalaru commited on
Commit
1da6442
Β·
verified Β·
1 Parent(s): 2fccdca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -14
app.py CHANGED
@@ -3,9 +3,7 @@ import os
3
  import datetime
4
  import json
5
  import tempfile
6
- import matplotlib.pyplot as plt
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
- # # === Updated Progress Tab ===
176
- # with gr.Tab("Progress πŸ“ˆ"):
177
- # gr.Markdown("### Your Learning Progress")
178
-
179
- # progress_label = gr.Label()
180
- # trend_plot = gr.Image(type="pil", label="Error Trend")
181
- # cat_plot = gr.Image(type="pil", label="Error Categories")
182
- # streak_label = gr.Label()
 
183
 
184
- # load_btn = gr.Button("Load Progress")
185
- # load_btn.click(calculate_progress, outputs=[progress_label, trend_plot, cat_plot, streak_label])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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("Error tracking & progress visualization coming soon!")
 
 
 
 
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 ===