Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,9 @@
|
|
| 1 |
-
|
| 2 |
import pandas as pd
|
| 3 |
from sklearn.linear_model import LogisticRegression
|
| 4 |
from sklearn.preprocessing import StandardScaler
|
| 5 |
import io
|
| 6 |
|
| 7 |
-
app = FastAPI(title="Employee of the Month API")
|
| 8 |
-
|
| 9 |
# ------------------------
|
| 10 |
# تدريب الموديل الأساسي
|
| 11 |
# ------------------------
|
|
@@ -27,22 +25,31 @@ model = LogisticRegression(class_weight='balanced')
|
|
| 27 |
model.fit(X_train_scaled, y_train)
|
| 28 |
|
| 29 |
# ------------------------
|
| 30 |
-
#
|
| 31 |
# ------------------------
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# قراءة ملف Excel
|
| 35 |
-
contents = await file.read()
|
| 36 |
-
df_new = pd.read_excel(io.BytesIO(contents))
|
| 37 |
|
| 38 |
-
# تجهيز البيانات الجديدة
|
| 39 |
X_new_scaled = scaler.transform(df_new[['PerformanceScore', 'ProjectsCompleted', 'Attendance']])
|
| 40 |
probs = model.predict_proba(X_new_scaled)[:, 1]
|
| 41 |
df_new['ProbabilityOfBeingBest'] = probs
|
| 42 |
|
| 43 |
best_employee = df_new.loc[df_new['ProbabilityOfBeingBest'].idxmax()]
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
"
|
|
|
|
| 47 |
}
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
from sklearn.linear_model import LogisticRegression
|
| 4 |
from sklearn.preprocessing import StandardScaler
|
| 5 |
import io
|
| 6 |
|
|
|
|
|
|
|
| 7 |
# ------------------------
|
| 8 |
# تدريب الموديل الأساسي
|
| 9 |
# ------------------------
|
|
|
|
| 25 |
model.fit(X_train_scaled, y_train)
|
| 26 |
|
| 27 |
# ------------------------
|
| 28 |
+
# دالة التنبؤ
|
| 29 |
# ------------------------
|
| 30 |
+
def predict_employee(file):
|
| 31 |
+
df_new = pd.read_excel(file)
|
|
|
|
|
|
|
|
|
|
| 32 |
|
|
|
|
| 33 |
X_new_scaled = scaler.transform(df_new[['PerformanceScore', 'ProjectsCompleted', 'Attendance']])
|
| 34 |
probs = model.predict_proba(X_new_scaled)[:, 1]
|
| 35 |
df_new['ProbabilityOfBeingBest'] = probs
|
| 36 |
|
| 37 |
best_employee = df_new.loc[df_new['ProbabilityOfBeingBest'].idxmax()]
|
| 38 |
+
|
| 39 |
+
return {
|
| 40 |
+
"Best Employee ID": int(best_employee['EmployeeID']),
|
| 41 |
+
"Probability": float(best_employee['ProbabilityOfBeingBest'])
|
| 42 |
}
|
| 43 |
+
|
| 44 |
+
# ------------------------
|
| 45 |
+
# واجهة Gradio
|
| 46 |
+
# ------------------------
|
| 47 |
+
iface = gr.Interface(
|
| 48 |
+
fn=predict_employee,
|
| 49 |
+
inputs=gr.File(label="Upload Excel File (.xlsx)"),
|
| 50 |
+
outputs="json",
|
| 51 |
+
title="Employee of the Month Predictor",
|
| 52 |
+
description="Upload an Excel file containing 'EmployeeID', 'PerformanceScore', 'ProjectsCompleted', and 'Attendance' columns to find the best employee."
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
iface.launch()
|