Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,6 +67,12 @@ def analyze_text(user_input):
|
|
| 67 |
|
| 68 |
corrected_text = response.choices[0].message.content # β
fixed
|
| 69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
# Save history
|
| 71 |
with open(HISTORY_FILE, "r+") as f:
|
| 72 |
history = json.load(f)
|
|
@@ -169,57 +175,58 @@ def save_plot_to_base64():
|
|
| 169 |
buf.close()
|
| 170 |
return "data:image/png;base64," + encoded
|
| 171 |
|
|
|
|
| 172 |
|
| 173 |
-
#
|
| 174 |
-
|
| 175 |
-
"
|
| 176 |
-
"
|
| 177 |
-
"
|
| 178 |
-
"
|
| 179 |
-
"
|
| 180 |
-
"badge": None
|
| 181 |
}
|
| 182 |
|
| 183 |
def update_daily_stats(is_correct: bool):
|
| 184 |
-
"""Update
|
| 185 |
today = str(datetime.date.today())
|
| 186 |
|
| 187 |
-
#
|
| 188 |
-
if
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
"badge": None
|
| 196 |
-
})
|
| 197 |
-
|
| 198 |
-
DAILY_STATS["attempts"] += 1
|
| 199 |
-
|
| 200 |
if is_correct:
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
if
|
| 204 |
-
|
|
|
|
| 205 |
else:
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
return get_progress_summary()
|
| 210 |
|
| 211 |
def get_progress_summary():
|
| 212 |
-
"""Return formatted
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
)
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
|
| 224 |
# # === Inside Gradio UI ===
|
| 225 |
# with gr.Tab("Progress π"):
|
|
@@ -260,12 +267,19 @@ with gr.Blocks() as demo:
|
|
| 260 |
# with gr.Tab("Progress π"):
|
| 261 |
# gr.Markdown("Error tracking & progress visualization coming soon!")
|
| 262 |
with gr.Tab("Progress π"):
|
| 263 |
-
|
| 264 |
-
progress_box = gr.Textbox(label="Todayβs Stats", interactive=False, lines=8)
|
| 265 |
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
|
| 270 |
# === Launch ===
|
| 271 |
demo.launch()
|
|
|
|
| 67 |
|
| 68 |
corrected_text = response.choices[0].message.content # β
fixed
|
| 69 |
|
| 70 |
+
if "β
Correct" in response or "No errors" in response:
|
| 71 |
+
update_daily_stats(is_correct=True)
|
| 72 |
+
else:
|
| 73 |
+
update_daily_stats(is_correct=False)
|
| 74 |
+
|
| 75 |
+
return response
|
| 76 |
# Save history
|
| 77 |
with open(HISTORY_FILE, "r+") as f:
|
| 78 |
history = json.load(f)
|
|
|
|
| 175 |
buf.close()
|
| 176 |
return "data:image/png;base64," + encoded
|
| 177 |
|
| 178 |
+
import datetime
|
| 179 |
|
| 180 |
+
# keep progress data in memory (you can later persist to file/db if needed)
|
| 181 |
+
progress_data = {
|
| 182 |
+
"today": str(datetime.date.today()),
|
| 183 |
+
"correct_count": 0,
|
| 184 |
+
"incorrect_count": 0,
|
| 185 |
+
"streak": 0,
|
| 186 |
+
"badges": []
|
|
|
|
| 187 |
}
|
| 188 |
|
| 189 |
def update_daily_stats(is_correct: bool):
|
| 190 |
+
"""Update today's progress based on correctness."""
|
| 191 |
today = str(datetime.date.today())
|
| 192 |
|
| 193 |
+
# Reset stats if a new day has started
|
| 194 |
+
if progress_data["today"] != today:
|
| 195 |
+
progress_data["today"] = today
|
| 196 |
+
progress_data["correct_count"] = 0
|
| 197 |
+
progress_data["incorrect_count"] = 0
|
| 198 |
+
progress_data["streak"] = 0
|
| 199 |
+
progress_data["badges"] = []
|
| 200 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
if is_correct:
|
| 202 |
+
progress_data["correct_count"] += 1
|
| 203 |
+
progress_data["streak"] += 1
|
| 204 |
+
# Award badge if streak hits 5
|
| 205 |
+
if progress_data["streak"] == 5:
|
| 206 |
+
progress_data["badges"].append("π
5-in-a-row Champion")
|
| 207 |
else:
|
| 208 |
+
progress_data["incorrect_count"] += 1
|
| 209 |
+
progress_data["streak"] = 0
|
| 210 |
+
|
|
|
|
| 211 |
|
| 212 |
def get_progress_summary():
|
| 213 |
+
"""Return a formatted summary for Gradio UI."""
|
| 214 |
+
today = progress_data["today"]
|
| 215 |
+
correct = progress_data["correct_count"]
|
| 216 |
+
incorrect = progress_data["incorrect_count"]
|
| 217 |
+
streak = progress_data["streak"]
|
| 218 |
+
badges = ", ".join(progress_data["badges"]) if progress_data["badges"] else "None yet"
|
| 219 |
+
|
| 220 |
+
summary = (
|
| 221 |
+
f"π
Date: {today}\n"
|
| 222 |
+
f"β
Correct: {correct}\n"
|
| 223 |
+
f"β Incorrect: {incorrect}\n"
|
| 224 |
+
f"π₯ Current Streak: {streak}\n"
|
| 225 |
+
f"π
Badges: {badges}"
|
| 226 |
)
|
| 227 |
+
return summary
|
| 228 |
+
|
| 229 |
+
|
| 230 |
|
| 231 |
# # === Inside Gradio UI ===
|
| 232 |
# with gr.Tab("Progress π"):
|
|
|
|
| 267 |
# with gr.Tab("Progress π"):
|
| 268 |
# gr.Markdown("Error tracking & progress visualization coming soon!")
|
| 269 |
with gr.Tab("Progress π"):
|
| 270 |
+
gr.Markdown("### π Daily Progress Tracker")
|
|
|
|
| 271 |
|
| 272 |
+
progress_box = gr.Textbox(
|
| 273 |
+
label="Today's Progress",
|
| 274 |
+
interactive=False,
|
| 275 |
+
lines=8,
|
| 276 |
+
value="No progress yet. Try practicing!"
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
refresh_btn = gr.Button("π Refresh Progress")
|
| 280 |
+
|
| 281 |
+
# β
bind refresh button here
|
| 282 |
+
refresh_btn.click(get_progress_summary, outputs=progress_box)
|
| 283 |
|
| 284 |
# === Launch ===
|
| 285 |
demo.launch()
|