Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,26 +6,28 @@ import plotly.graph_objects as go
|
|
| 6 |
|
| 7 |
# Define admin credentials
|
| 8 |
ADMIN_EMAIL = "admin@gmail.com"
|
| 9 |
-
ADMIN_PASSWORD = "
|
| 10 |
|
| 11 |
# Variable to store uploaded grades file in memory
|
| 12 |
grades_df = None
|
| 13 |
|
| 14 |
# Admin login function
|
| 15 |
-
def
|
| 16 |
-
if email == ADMIN_EMAIL and password == ADMIN_PASSWORD:
|
| 17 |
-
return (
|
| 18 |
else:
|
| 19 |
-
|
| 20 |
|
|
|
|
|
|
|
| 21 |
def intern_login(email):
|
| 22 |
-
return (
|
| 23 |
|
| 24 |
# Admin upload function
|
| 25 |
def admin_upload(file):
|
| 26 |
global grades_df
|
| 27 |
if file is not None:
|
| 28 |
-
grades_df = pd.read_excel(
|
| 29 |
return "File uploaded and processed successfully."
|
| 30 |
else:
|
| 31 |
return "Please upload a valid Excel file."
|
|
@@ -43,14 +45,15 @@ def performance_analysis():
|
|
| 43 |
# Line chart for daily performance
|
| 44 |
line_chart = px.line(daily_performance, x='Date', y='Grade', title='Daily Performance (Total Grades)')
|
| 45 |
|
|
|
|
| 46 |
# Histogram of grades
|
| 47 |
-
histogram = px.histogram(
|
| 48 |
|
| 49 |
# Box plot for grade statistics
|
| 50 |
-
box_plot = px.box(
|
| 51 |
|
| 52 |
# Create a summary table
|
| 53 |
-
summary_stats =
|
| 54 |
summary_table = go.Figure(data=[go.Table(
|
| 55 |
header=dict(values=['Statistic', 'Value']),
|
| 56 |
cells=dict(values=[summary_stats['index'], summary_stats['Grade']])
|
|
@@ -60,56 +63,106 @@ def performance_analysis():
|
|
| 60 |
else:
|
| 61 |
return None, None, None, None
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Create the Gradio interface
|
| 64 |
with gr.Blocks() as demo:
|
| 65 |
with gr.Tab("Admin Login"):
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
admin_submit = gr.Button("Submit", visible=False)
|
| 72 |
-
admin_file_output = gr.Textbox(label="File Upload Output", visible=False)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
admin_login_button.click(
|
| 80 |
-
|
| 81 |
inputs=[admin_email, admin_password],
|
| 82 |
-
outputs=[
|
| 83 |
-
show_progress=
|
| 84 |
)
|
| 85 |
admin_submit.click(
|
| 86 |
admin_upload,
|
| 87 |
inputs=[admin_file],
|
| 88 |
outputs=admin_file_output,
|
| 89 |
)
|
| 90 |
-
|
| 91 |
performance_analysis,
|
| 92 |
outputs=[admin_charts, admin_histogram, admin_box_plot, admin_summary_table],
|
| 93 |
)
|
| 94 |
|
| 95 |
with gr.Tab("Intern Login"):
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
| 101 |
|
| 102 |
intern_login_button.click(
|
| 103 |
intern_login,
|
| 104 |
inputs=[intern_email],
|
| 105 |
-
outputs=[
|
| 106 |
-
show_progress=
|
| 107 |
-
)
|
| 108 |
-
intern_submit.click(
|
| 109 |
-
intern_view,
|
| 110 |
-
inputs=[intern_email],
|
| 111 |
-
outputs=intern_output,
|
| 112 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
# Launch the app
|
| 115 |
-
demo.launch()
|
|
|
|
| 6 |
|
| 7 |
# Define admin credentials
|
| 8 |
ADMIN_EMAIL = "admin@gmail.com"
|
| 9 |
+
ADMIN_PASSWORD = "admin"
|
| 10 |
|
| 11 |
# Variable to store uploaded grades file in memory
|
| 12 |
grades_df = None
|
| 13 |
|
| 14 |
# Admin login function
|
| 15 |
+
def admin_login_function(email, password):
|
| 16 |
+
if True or (email == ADMIN_EMAIL and password == ADMIN_PASSWORD):
|
| 17 |
+
return gr.update(visible=False), gr.update(visible=True),
|
| 18 |
else:
|
| 19 |
+
raise gr.Error("wrong password 💥!", duration=5)
|
| 20 |
|
| 21 |
+
|
| 22 |
+
# Intern login function
|
| 23 |
def intern_login(email):
|
| 24 |
+
return gr.update(visible=False), gr.update(visible=True), intern_view(email)
|
| 25 |
|
| 26 |
# Admin upload function
|
| 27 |
def admin_upload(file):
|
| 28 |
global grades_df
|
| 29 |
if file is not None:
|
| 30 |
+
grades_df = pd.read_excel(file.name)
|
| 31 |
return "File uploaded and processed successfully."
|
| 32 |
else:
|
| 33 |
return "Please upload a valid Excel file."
|
|
|
|
| 45 |
# Line chart for daily performance
|
| 46 |
line_chart = px.line(daily_performance, x='Date', y='Grade', title='Daily Performance (Total Grades)')
|
| 47 |
|
| 48 |
+
email_performance = grades_df.groupby('Email')['Grade'].sum().reset_index()
|
| 49 |
# Histogram of grades
|
| 50 |
+
histogram = px.histogram(email_performance, x='Grade', nbins=20, title='Grade Distribution')
|
| 51 |
|
| 52 |
# Box plot for grade statistics
|
| 53 |
+
box_plot = px.box(email_performance, y='Grade', title='Grade Statistics')
|
| 54 |
|
| 55 |
# Create a summary table
|
| 56 |
+
summary_stats = email_performance['Grade'].describe().reset_index()
|
| 57 |
summary_table = go.Figure(data=[go.Table(
|
| 58 |
header=dict(values=['Statistic', 'Value']),
|
| 59 |
cells=dict(values=[summary_stats['index'], summary_stats['Grade']])
|
|
|
|
| 63 |
else:
|
| 64 |
return None, None, None, None
|
| 65 |
|
| 66 |
+
MAX_SCORE = 100 # Assuming the maximum possible score is 100
|
| 67 |
+
|
| 68 |
+
def intern_view(email):
|
| 69 |
+
if grades_df is not None:
|
| 70 |
+
intern_grades = grades_df[grades_df['Email'] == email]
|
| 71 |
+
if not intern_grades.empty:
|
| 72 |
+
total_grade = intern_grades['Grade'].sum()
|
| 73 |
+
average_grade = intern_grades['Grade'].mean()
|
| 74 |
+
num_records = intern_grades.shape[0]
|
| 75 |
+
|
| 76 |
+
# Normalize the score to MAX_SCORE
|
| 77 |
+
normalized_score = min(total_grade / MAX_SCORE, 1)
|
| 78 |
+
|
| 79 |
+
# Determine the color level
|
| 80 |
+
if normalized_score <= 0.2:
|
| 81 |
+
color = "red"
|
| 82 |
+
elif normalized_score <= 0.4:
|
| 83 |
+
color = "orange"
|
| 84 |
+
elif normalized_score <= 0.6:
|
| 85 |
+
color = "yellow"
|
| 86 |
+
elif normalized_score <= 0.8:
|
| 87 |
+
color = "lightgreen"
|
| 88 |
+
else:
|
| 89 |
+
color = "green"
|
| 90 |
+
|
| 91 |
+
# Return as a Markdown formatted string
|
| 92 |
+
return f"""
|
| 93 |
+
### Grade Analysis for {email}
|
| 94 |
+
|
| 95 |
+
- **Total Grade**: {normalized_score}
|
| 96 |
+
- **Number of Records**: {num_records}
|
| 97 |
+
|
| 98 |
+
<div style="background-color:{color}; padding:10px; border-radius:5px;">
|
| 99 |
+
**Performance Level**: {color.capitalize()}
|
| 100 |
+
</div>
|
| 101 |
+
"""
|
| 102 |
+
else:
|
| 103 |
+
return "No records found for this email."
|
| 104 |
+
else:
|
| 105 |
+
return "No grades file uploaded. Please contact the admin."
|
| 106 |
+
|
| 107 |
+
|
| 108 |
# Create the Gradio interface
|
| 109 |
with gr.Blocks() as demo:
|
| 110 |
with gr.Tab("Admin Login"):
|
| 111 |
+
with gr.Column(visible=True) as admin_login_section:
|
| 112 |
+
admin_email = gr.Textbox(label="Admin Email")
|
| 113 |
+
admin_password = gr.Textbox(label="Admin Password", type="password")
|
| 114 |
+
admin_login_button = gr.Button("Login")
|
| 115 |
+
admin_login_output = gr.Textbox(label="Admin Output")
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
with gr.Column(visible=False) as admin_upload_section:
|
| 118 |
+
with gr.Column() as update_file_section:
|
| 119 |
+
admin_file = gr.File(label="Upload Grades Excel File")
|
| 120 |
+
admin_submit = gr.Button("Submit")
|
| 121 |
+
admin_file_output = gr.Textbox(label="File Upload Output")
|
| 122 |
+
|
| 123 |
+
admin_analyze = gr.Button("Analyze")
|
| 124 |
+
admin_charts = gr.Plot()
|
| 125 |
+
admin_histogram = gr.Plot()
|
| 126 |
+
admin_box_plot = gr.Plot()
|
| 127 |
+
admin_summary_table = gr.Plot()
|
| 128 |
|
| 129 |
admin_login_button.click(
|
| 130 |
+
admin_login_function,
|
| 131 |
inputs=[admin_email, admin_password],
|
| 132 |
+
outputs=[admin_login_section, admin_upload_section],
|
| 133 |
+
show_progress=True,
|
| 134 |
)
|
| 135 |
admin_submit.click(
|
| 136 |
admin_upload,
|
| 137 |
inputs=[admin_file],
|
| 138 |
outputs=admin_file_output,
|
| 139 |
)
|
| 140 |
+
admin_analyze.click(
|
| 141 |
performance_analysis,
|
| 142 |
outputs=[admin_charts, admin_histogram, admin_box_plot, admin_summary_table],
|
| 143 |
)
|
| 144 |
|
| 145 |
with gr.Tab("Intern Login"):
|
| 146 |
+
with gr.Column(visible=True) as intern_login_section:
|
| 147 |
+
intern_email = gr.Textbox(label="Intern Email")
|
| 148 |
+
intern_login_button = gr.Button("Find")
|
| 149 |
+
intern_login_output = gr.Textbox(label="Intern Output")
|
| 150 |
+
|
| 151 |
+
with gr.Column(visible=False) as intern_info_section:
|
| 152 |
+
intern_output = gr.Markdown(label="Grade Analysis")
|
| 153 |
|
| 154 |
intern_login_button.click(
|
| 155 |
intern_login,
|
| 156 |
inputs=[intern_email],
|
| 157 |
+
outputs=[intern_login_section, intern_info_section, intern_output],
|
| 158 |
+
show_progress=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
)
|
| 160 |
+
|
| 161 |
+
# intern_submit.click(
|
| 162 |
+
# intern_view,
|
| 163 |
+
# inputs=[intern_email],
|
| 164 |
+
# outputs=intern_output,
|
| 165 |
+
# )
|
| 166 |
|
| 167 |
# Launch the app
|
| 168 |
+
demo.launch(debug=True)
|