import gradio as gr import pandas as pd import io # Define admin credentials ADMIN_EMAIL = "admin@gmail.com" ADMIN_PASSWORD = "123456" # Variable to store uploaded grades file in memory grades_df = None # Admin upload function def admin_upload(email, password, file): global grades_df if email == ADMIN_EMAIL and password == ADMIN_PASSWORD: if file is not None: # Read the uploaded file in-memory grades_df = pd.read_excel(io.BytesIO(file.read())) return "File uploaded and processed successfully." else: return "Please upload a valid Excel file." else: return "Invalid credentials." # Intern grade analysis function def intern_view(email): if grades_df is not None: # Filter the grades for the provided email intern_grades = grades_df[grades_df['Email'] == email] if not intern_grades.empty: # Generate a summary analysis total_grade = intern_grades['Grade'].sum() average_grade = intern_grades['Grade'].mean() num_records = intern_grades.shape[0] return ( f"Total Grade: {total_grade}\n" f"Average Grade: {average_grade}\n" f"Number of Records: {num_records}\n" ) else: return "No records found for this email." else: return "No grades file uploaded. Please contact the admin." # Create the Gradio interface with gr.Blocks() as demo: with gr.Tab("Admin Login"): with gr.Row(): admin_email = gr.Textbox(label="Admin Email") admin_password = gr.Textbox(label="Admin Password", type="password") admin_file = gr.File(label="Upload Grades Excel File") admin_submit = gr.Button("Submit") admin_output = gr.Textbox(label="Admin Output") admin_submit.click( admin_upload, inputs=[admin_email, admin_password, admin_file], outputs=admin_output, ) with gr.Tab("Intern Login"): with gr.Row(): intern_email = gr.Textbox(label="Intern Email") intern_submit = gr.Button("View Grades") intern_output = gr.Textbox(label="Intern Output") intern_submit.click( intern_view, inputs=[intern_email], outputs=intern_output, ) # Launch the app demo.launch()