Fah commited on
Commit
196c02e
1 Parent(s): a5ecd5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -7,14 +7,15 @@ from pycaret.regression import *
7
  cvr_saved = load_model('pred_cvr')
8
 
9
  def predict_cvr(xyz_campaign_id, gender, age, Impressions, Clicks,
10
- Total_Conversion, interest): #สร้าง function predict_cvr โดยภายใน function คือ ส่วนของ input data
11
- path = "KAG_conversion_data.csv" #Import development ไฟล์ที่เป็น .csv
12
- df = pd.read_csv(path) #อ่านไฟล์ csv
13
- df.drop(["ad_id", "fb_campaign_id", "Spent","Approved_Conversion"],axis=1, inplace = True) #drop columns ทิ้ง
14
- df = pd.DataFrame.from_dict({'xyz_campaign_id': [xyz_campaign_id], 'gender': [gender], 'age': [age], 'Impressions': [Impressions], 'Clicks': [Clicks], 'Total_Conversion': [Total_Conversion], 'interest': [interest]}) #แปลงเป็น dataframe
15
- df["xyz_campaign_id"].replace({916:"campaign_a",936:"campaign_b",1178:"campaign_c"}, inplace=True) #แทนที่ด้วยชื่อ campaign
16
- pred = cvr_saved.predict(df).tolist()[0] #เมื่่อถูกทำนายแล้ว มันจะส่งกลับคืนค่าเข้าไปใน pred
17
- return 'Conversion Rate : '+str(pred) #function predict_cvr จะส่ง output ออกมาเป็น "Conversion Rate : pred"
 
18
 
19
  xyz_campaign_id = gr.inputs.Dropdown(['campaign_a', 'campaign_b', 'campaign_c'], label="xyz_campaign_id -> an ID associated with each ad campaign of XYZ company")
20
  gender = gr.inputs.Dropdown(['M', 'F'], label = "gender -> gender of the person to whom the add is shown")
 
7
  cvr_saved = load_model('pred_cvr')
8
 
9
  def predict_cvr(xyz_campaign_id, gender, age, Impressions, Clicks,
10
+ Total_Conversion, interest):
11
+ path = "KAG_conversion_data.csv"
12
+ df = pd.read_csv(path)
13
+ df.drop(["ad_id", "fb_campaign_id", "Spent","Approved_Conversion"],axis=1, inplace = True)
14
+ df = pd.DataFrame.from_dict({'xyz_campaign_id': [xyz_campaign_id], 'gender': [gender], 'age': [age], 'Impressions': [Impressions],
15
+ 'Clicks': [Clicks], 'Total_Conversion': [Total_Conversion], 'interest': [interest]})
16
+ df["xyz_campaign_id"].replace({916:"campaign_a",936:"campaign_b",1178:"campaign_c"}, inplace=True)
17
+ pred = cvr_saved.predict(df).tolist()[0]
18
+ return 'Conversion Rate : '+str(pred)
19
 
20
  xyz_campaign_id = gr.inputs.Dropdown(['campaign_a', 'campaign_b', 'campaign_c'], label="xyz_campaign_id -> an ID associated with each ad campaign of XYZ company")
21
  gender = gr.inputs.Dropdown(['M', 'F'], label = "gender -> gender of the person to whom the add is shown")