import matplotlib.pyplot as plt import numpy as np from io import BytesIO import base64 cheating_scores = [] def plot_cheating_graph(): fig, ax = plt.subplots() ax.plot(cheating_scores, color='red', label='Cheating Score') ax.set_xlabel("Time") ax.set_ylabel("Cheating Probability") ax.set_title("Live Cheating Detection Graph") ax.legend() buf = BytesIO() plt.savefig(buf, format='png') buf.seek(0) encoded = base64.b64encode(buf.read()).decode('utf-8') plt.close(fig) return f"data:image/png;base64,{encoded}" def update_score(cheating): score = 1 if cheating else 0 cheating_scores.append(score) if len(cheating_scores) > 50: cheating_scores.pop(0)