import gradio as gr import pandas as pd import io import plotly.express as px import plotly.graph_objects as go import os # Define admin credentials ADMIN_EMAIL = os.environ["ACCOUNT"] ADMIN_PASSWORD = os.environ["PASSWORD"] # Variable to store uploaded grades file in memory grades_df = None # Admin login function def admin_login_function(email, password): if (email == ADMIN_EMAIL and password == ADMIN_PASSWORD): return gr.update(visible=False), gr.update(visible=True), else: raise gr.Error("wrong password 💥!", duration=5) # Intern login function def intern_login(email): results = intern_view(email) return gr.update(visible=False), gr.update(visible=True), results[0], results[1] # Admin upload function def admin_upload(file): global grades_df if file is not None: grades_df = pd.read_excel(file.name) return "File uploaded and processed successfully." else: return "Please upload a valid Excel file." # Function to generate performance analysis charts def performance_analysis(): if grades_df is not None: # Ensure 'Created At' is datetime grades_df['Created At'] = pd.to_datetime(grades_df['Created At']) grades_df['Date'] = grades_df['Created At'].dt.date # Group by date and calculate sum of grades daily_performance = grades_df.groupby('Date')['Grade'].sum().reset_index() # Line chart for daily performance line_chart = px.line(daily_performance, x='Date', y='Grade', title='Daily Performance (Total Grades)') email_performance = grades_df.groupby('Email')['Grade'].sum().reset_index() # Histogram of grades histogram = px.histogram(email_performance, x='Grade', nbins=20, title='Grade Distribution') # Box plot for grade statistics box_plot = px.box(email_performance, y='Grade', title='Grade Statistics') # Create a summary table summary_stats = email_performance['Grade'].describe().reset_index() summary_table = go.Figure(data=[go.Table( header=dict(values=['Statistic', 'Value']), cells=dict(values=[summary_stats['index'], summary_stats['Grade']]) )]) return line_chart, histogram, box_plot, summary_table else: return None, None, None, None MAX_SCORE = 25*2 # Assuming the maximum possible score is 100 def intern_view(email): if grades_df is not None: intern_grades = grades_df[grades_df['Email'] == email] daily_performance = intern_grades.groupby('Date')['Grade'].sum().reset_index() line_chart = px.line(daily_performance, x='Date', y='Grade', title='Daily Performance (Total Grades)') if not intern_grades.empty: total_grade = intern_grades['Grade'].sum() average_grade = intern_grades['Grade'].mean() num_records = intern_grades.shape[0] # Normalize the score to MAX_SCORE normalized_score = min(total_grade / MAX_SCORE, 1) # Determine the color level if normalized_score <= 0.8: color = "red" else: color = "green" #