Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| from sklearn.linear_model import LogisticRegression | |
| from sklearn.preprocessing import StandardScaler | |
| import io | |
| # ------------------------ | |
| # تدريب الموديل الأساسي | |
| # ------------------------ | |
| df_train = pd.DataFrame({ | |
| 'EmployeeID': [101, 102, 103, 104, 105, 106], | |
| 'PerformanceScore': [90, 85, 95, 80, 88, 92], | |
| 'ProjectsCompleted': [5, 6, 7, 4, 6, 5], | |
| 'Attendance': [98, 92, 95, 90, 97, 96], | |
| 'EmployeeOfTheMonth': [0, 0, 1, 0, 0, 0] | |
| }) | |
| X_train = df_train[['PerformanceScore', 'ProjectsCompleted', 'Attendance']] | |
| y_train = df_train['EmployeeOfTheMonth'] | |
| scaler = StandardScaler() | |
| X_train_scaled = scaler.fit_transform(X_train) | |
| model = LogisticRegression(class_weight='balanced') | |
| model.fit(X_train_scaled, y_train) | |
| # ------------------------ | |
| # دالة التنبؤ | |
| # ------------------------ | |
| def predict_employee(file): | |
| df_new = pd.read_excel(file) | |
| X_new_scaled = scaler.transform(df_new[['PerformanceScore', 'ProjectsCompleted', 'Attendance']]) | |
| probs = model.predict_proba(X_new_scaled)[:, 1] | |
| df_new['ProbabilityOfBeingBest'] = probs | |
| best_employee = df_new.loc[df_new['ProbabilityOfBeingBest'].idxmax()] | |
| return { | |
| "Best Employee ID": int(best_employee['EmployeeID']), | |
| "Probability": float(best_employee['ProbabilityOfBeingBest']) | |
| } | |
| # ------------------------ | |
| # واجهة Gradio | |
| # ------------------------ | |
| iface = gr.Interface( | |
| fn=predict_employee, | |
| inputs=gr.File(label="Upload Excel File (.xlsx)"), | |
| outputs="json", | |
| title="Employee of the Month Predictor", | |
| description="Upload an Excel file containing 'EmployeeID', 'PerformanceScore', 'ProjectsCompleted', and 'Attendance' columns to find the best employee." | |
| ) | |
| iface.launch(share=True) | |