mohamed20003 commited on
Commit
ace6c2e
·
verified ·
1 Parent(s): 3193856

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -14
app.py CHANGED
@@ -1,11 +1,9 @@
1
- from fastapi import FastAPI, UploadFile, File
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
- # API Endpoint
31
  # ------------------------
32
- @app.post("/predict")
33
- async def predict_employee(file: UploadFile = File(...)):
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
- result = {
45
- "BestEmployeeID": int(best_employee['EmployeeID']),
46
- "Probability": float(best_employee['ProbabilityOfBeingBest']),
 
47
  }
48
- return result
 
 
 
 
 
 
 
 
 
 
 
 
 
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()