123ahmed commited on
Commit
c8a0d5f
·
verified ·
1 Parent(s): 2d6c379

Upload 5 files

Browse files
Files changed (5) hide show
  1. app.py +65 -0
  2. le_col.pkl +3 -0
  3. model.pkl +3 -0
  4. requirements.txt +5 -0
  5. st_col.pkl +3 -0
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ os.system("pip install joblib pandas scikit-learn gradio")
3
+ import joblib
4
+
5
+
6
+ import pandas as pd
7
+ import joblib
8
+ import gradio as gr
9
+
10
+ # تحميل الكائنات المحفوظة
11
+ le = joblib.load("le_col.pkl") # Label Encoders
12
+ std = joblib.load("st_col.pkl") # Standard Scaler
13
+ lr = joblib.load("model.pkl") # نموذج الانحدار اللوجستي
14
+
15
+ # الأعمدة التي تحتاج إلى التحويل والتقييس
16
+ le_col = ['Segment', 'Market', 'Category']
17
+ st_col = ['Sales', 'Quantity', 'Profit', 'Shipping Cost']
18
+
19
+ def prediction_model(s, m, c, ss, q, d, p, ssc):
20
+ try:
21
+ # تجهيز البيانات المدخلة
22
+ input_data = pd.DataFrame({
23
+ 'Segment': [s],
24
+ 'Market': [m],
25
+ 'Category': [c],
26
+ 'Sales': [ss],
27
+ 'Quantity': [q],
28
+ 'Discount': [d],
29
+ 'Profit': [p],
30
+ 'Shipping Cost': [ssc]
31
+ })
32
+
33
+ # تحويل القيم الفئوية باستخدام LabelEncoder المحفوظ
34
+ for col in le_col:
35
+ input_data[col] = le[col].transform(input_data[col])
36
+ # تقييس البيانات العددية باستخدام StandardScaler المحفوظ
37
+ input_data[st_col] = std.transform(input_data[st_col])
38
+
39
+ # التنبؤ باستخدام النموذج المحفوظ
40
+ prediction = lr.predict(input_data)
41
+ if prediction[0] == 0:
42
+ return 'High'
43
+ else:
44
+ return 'Low'
45
+
46
+
47
+ except Exception as e:
48
+ return str(e)
49
+
50
+ # بناء واجهة Gradio
51
+ gr.Interface(
52
+ fn=prediction_model,
53
+ inputs=[
54
+ gr.Dropdown(['Consumer', 'Corporate', 'Home Office'], label='Segment'),
55
+ gr.Dropdown(['Asia Pacific', 'Europe', 'USCA', 'LATAM', 'Africa'], label='Market'),
56
+ gr.Dropdown(['Technology', 'Furniture', 'Office Supplies'], label='Category'),
57
+ gr.Number(label='Sales'),
58
+ gr.Number(label='Quantity'),
59
+ gr.Number(label='Discount'),
60
+ gr.Number(label='Profit'),
61
+ gr.Number(label='Shipping Cost')
62
+ ],
63
+ outputs=gr.Textbox(label='Prediction'),
64
+ title='Prediction Program'
65
+ ).launch()
le_col.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d9dcff71881792f383d30ad42876b6ddd90b89ae5acc3aa4ec93cf31e2668071
3
+ size 1232
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a4c5083c264bfa35c33b3de63f4a6145e1820b6e822c44f1c2fbcd964fbb0fec
3
+ size 1503
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ scikit-learn==1.0.2
4
+ joblib
5
+ gradio
st_col.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58ef23f624153b364e8b5fbcf548de05f1328f309384e7e7433fd891171041c7
3
+ size 1063