123ahmed's picture
Upload 5 files
c8a0d5f verified
import os
os.system("pip install joblib pandas scikit-learn gradio")
import joblib
import pandas as pd
import joblib
import gradio as gr
# تحميل الكائنات المحفوظة
le = joblib.load("le_col.pkl") # Label Encoders
std = joblib.load("st_col.pkl") # Standard Scaler
lr = joblib.load("model.pkl") # نموذج الانحدار اللوجستي
# الأعمدة التي تحتاج إلى التحويل والتقييس
le_col = ['Segment', 'Market', 'Category']
st_col = ['Sales', 'Quantity', 'Profit', 'Shipping Cost']
def prediction_model(s, m, c, ss, q, d, p, ssc):
try:
# تجهيز البيانات المدخلة
input_data = pd.DataFrame({
'Segment': [s],
'Market': [m],
'Category': [c],
'Sales': [ss],
'Quantity': [q],
'Discount': [d],
'Profit': [p],
'Shipping Cost': [ssc]
})
# تحويل القيم الفئوية باستخدام LabelEncoder المحفوظ
for col in le_col:
input_data[col] = le[col].transform(input_data[col])
# تقييس البيانات العددية باستخدام StandardScaler المحفوظ
input_data[st_col] = std.transform(input_data[st_col])
# التنبؤ باستخدام النموذج المحفوظ
prediction = lr.predict(input_data)
if prediction[0] == 0:
return 'High'
else:
return 'Low'
except Exception as e:
return str(e)
# بناء واجهة Gradio
gr.Interface(
fn=prediction_model,
inputs=[
gr.Dropdown(['Consumer', 'Corporate', 'Home Office'], label='Segment'),
gr.Dropdown(['Asia Pacific', 'Europe', 'USCA', 'LATAM', 'Africa'], label='Market'),
gr.Dropdown(['Technology', 'Furniture', 'Office Supplies'], label='Category'),
gr.Number(label='Sales'),
gr.Number(label='Quantity'),
gr.Number(label='Discount'),
gr.Number(label='Profit'),
gr.Number(label='Shipping Cost')
],
outputs=gr.Textbox(label='Prediction'),
title='Prediction Program'
).launch()