vietdata commited on
Commit
0b4a8f9
·
verified ·
1 Parent(s): 23a0c99

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -39
app.py CHANGED
@@ -1,6 +1,8 @@
1
  import gradio as gr
2
  import pandas as pd
3
  import io
 
 
4
 
5
  # Define admin credentials
6
  ADMIN_EMAIL = "[email protected]"
@@ -9,61 +11,97 @@ ADMIN_PASSWORD = "123456"
9
  # Variable to store uploaded grades file in memory
10
  grades_df = None
11
 
 
 
 
 
 
 
 
12
  # Admin upload function
13
- def admin_upload(email, password, file):
14
  global grades_df
15
- if email == ADMIN_EMAIL and password == ADMIN_PASSWORD:
16
- if file is not None:
17
- # Read the uploaded file in-memory
18
- grades_df = pd.read_excel(io.BytesIO(file.read()))
19
- return "File uploaded and processed successfully."
20
- else:
21
- return "Please upload a valid Excel file."
22
  else:
23
- return "Invalid credentials."
24
 
25
- # Intern grade analysis function
26
- def intern_view(email):
27
  if grades_df is not None:
28
- # Filter the grades for the provided email
29
- intern_grades = grades_df[grades_df['Email'] == email]
30
- if not intern_grades.empty:
31
- # Generate a summary analysis
32
- total_grade = intern_grades['Grade'].sum()
33
- average_grade = intern_grades['Grade'].mean()
34
- num_records = intern_grades.shape[0]
35
- return (
36
- f"Total Grade: {total_grade}\n"
37
- f"Average Grade: {average_grade}\n"
38
- f"Number of Records: {num_records}\n"
39
- )
40
- else:
41
- return "No records found for this email."
 
 
 
 
 
 
 
 
 
 
42
  else:
43
- return "No grades file uploaded. Please contact the admin."
44
 
45
  # Create the Gradio interface
46
  with gr.Blocks() as demo:
47
  with gr.Tab("Admin Login"):
48
- with gr.Row():
49
- admin_email = gr.Textbox(label="Admin Email")
50
- admin_password = gr.Textbox(label="Admin Password", type="password")
51
- admin_file = gr.File(label="Upload Grades Excel File")
52
- admin_submit = gr.Button("Submit")
53
- admin_output = gr.Textbox(label="Admin Output")
 
 
 
 
 
 
54
 
 
 
 
 
 
 
55
  admin_submit.click(
56
  admin_upload,
57
- inputs=[admin_email, admin_password, admin_file],
58
- outputs=admin_output,
 
 
 
 
59
  )
60
 
61
  with gr.Tab("Intern Login"):
62
- with gr.Row():
63
- intern_email = gr.Textbox(label="Intern Email")
64
- intern_submit = gr.Button("View Grades")
65
- intern_output = gr.Textbox(label="Intern Output")
 
66
 
 
 
 
 
 
 
67
  intern_submit.click(
68
  intern_view,
69
  inputs=[intern_email],
@@ -71,4 +109,4 @@ with gr.Blocks() as demo:
71
  )
72
 
73
  # Launch the app
74
- demo.launch()
 
1
  import gradio as gr
2
  import pandas as pd
3
  import io
4
+ import plotly.express as px
5
+ import plotly.graph_objects as go
6
 
7
  # Define admin credentials
8
  ADMIN_EMAIL = "[email protected]"
 
11
  # Variable to store uploaded grades file in memory
12
  grades_df = None
13
 
14
+ # Admin login function
15
+ def admin_login(email, password):
16
+ if email == ADMIN_EMAIL and password == ADMIN_PASSWORD:
17
+ return (True, "", "Logged in successfully.", True)
18
+ else:
19
+ return (False, "", "Invalid credentials.", False)
20
+
21
  # Admin upload function
22
+ def admin_upload(file):
23
  global grades_df
24
+ if file is not None:
25
+ grades_df = pd.read_excel(io.BytesIO(file.read()))
26
+ return "File uploaded and processed successfully."
 
 
 
 
27
  else:
28
+ return "Please upload a valid Excel file."
29
 
30
+ # Function to generate performance analysis charts
31
+ def performance_analysis():
32
  if grades_df is not None:
33
+ # Ensure 'Created At' is datetime
34
+ grades_df['Created At'] = pd.to_datetime(grades_df['Created At'])
35
+ grades_df['Date'] = grades_df['Created At'].dt.date
36
+
37
+ # Group by date and calculate sum of grades
38
+ daily_performance = grades_df.groupby('Date')['Grade'].sum().reset_index()
39
+
40
+ # Line chart for daily performance
41
+ line_chart = px.line(daily_performance, x='Date', y='Grade', title='Daily Performance (Total Grades)')
42
+
43
+ # Histogram of grades
44
+ histogram = px.histogram(grades_df, x='Grade', nbins=20, title='Grade Distribution')
45
+
46
+ # Box plot for grade statistics
47
+ box_plot = px.box(grades_df, y='Grade', title='Grade Statistics')
48
+
49
+ # Create a summary table
50
+ summary_stats = grades_df['Grade'].describe().reset_index()
51
+ summary_table = go.Figure(data=[go.Table(
52
+ header=dict(values=['Statistic', 'Value']),
53
+ cells=dict(values=[summary_stats['index'], summary_stats['Grade']])
54
+ )])
55
+
56
+ return line_chart, histogram, box_plot, summary_table
57
  else:
58
+ return None, None, None, None
59
 
60
  # Create the Gradio interface
61
  with gr.Blocks() as demo:
62
  with gr.Tab("Admin Login"):
63
+ admin_email = gr.Textbox(label="Admin Email")
64
+ admin_password = gr.Textbox(label="Admin Password", type="password")
65
+ admin_login_button = gr.Button("Login")
66
+ admin_login_output = gr.Textbox(label="Admin Output")
67
+ admin_file = gr.File(label="Upload Grades Excel File", visible=False)
68
+ admin_submit = gr.Button("Submit", visible=False)
69
+ admin_file_output = gr.Textbox(label="File Upload Output", visible=False)
70
+
71
+ admin_charts = gr.Plot(visible=False)
72
+ admin_histogram = gr.Plot(visible=False)
73
+ admin_box_plot = gr.Plot(visible=False)
74
+ admin_summary_table = gr.Plot(visible=False)
75
 
76
+ admin_login_button.click(
77
+ admin_login,
78
+ inputs=[admin_email, admin_password],
79
+ outputs=[admin_login_output, admin_file, admin_submit, admin_file_output],
80
+ show_progress=False,
81
+ )
82
  admin_submit.click(
83
  admin_upload,
84
+ inputs=[admin_file],
85
+ outputs=admin_file_output,
86
+ )
87
+ admin_submit.click(
88
+ performance_analysis,
89
+ outputs=[admin_charts, admin_histogram, admin_box_plot, admin_summary_table],
90
  )
91
 
92
  with gr.Tab("Intern Login"):
93
+ intern_email = gr.Textbox(label="Intern Email")
94
+ intern_login_button = gr.Button("Login")
95
+ intern_login_output = gr.Textbox(label="Intern Output")
96
+ intern_submit = gr.Button("View Grades", visible=False)
97
+ intern_output = gr.Textbox(label="Grade Analysis", visible=False)
98
 
99
+ intern_login_button.click(
100
+ intern_login,
101
+ inputs=[intern_email],
102
+ outputs=[intern_login_output, intern_submit, intern_output],
103
+ show_progress=False,
104
+ )
105
  intern_submit.click(
106
  intern_view,
107
  inputs=[intern_email],
 
109
  )
110
 
111
  # Launch the app
112
+ demo.launch()