Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
|
6 |
+
from pycaret.regression import *
|
7 |
+
|
8 |
+
# Set display results
|
9 |
+
pd.options.display.float_format = '{:,.4f}'.format
|
10 |
+
%config InlineBackend.figure_format = 'retina'
|
11 |
+
|
12 |
+
def predict_cvr(xyz_campaign_id, gender, age, Impressions, Clicks,
|
13 |
+
Total_Conversion, interest): #สร้าง function predict_cvr โดยภายใน function คือ ส่วนของ input data
|
14 |
+
path = "/content/drive/MyDrive/KAG_conversion_data.csv" #Import development ไฟล์ที่เป็น .csv
|
15 |
+
df = pd.read_csv(path) #อ่านไฟล์ csv
|
16 |
+
df.drop(["ad_id", "fb_campaign_id", "Spent","Approved_Conversion"],axis=1, inplace = True) #drop columns ทิ้ง
|
17 |
+
df = pd.DataFrame.from_dict({'xyz_campaign_id': [xyz_campaign_id], 'gender': [gender], 'age': [age], 'Impressions': [Impressions], 'Clicks': [Clicks],
|
18 |
+
'Total_Conversion': [Total_Conversion], 'interest': [interest]}) #แปลงเป็น dataframe
|
19 |
+
df["xyz_campaign_id"].replace({916:"campaign_a",936:"campaign_b",1178:"campaign_c"}, inplace=True) #แทนที่ด้วยชื่อ campaign
|
20 |
+
pred = cvr_saved.predict(df).tolist()[0] #เมื่่อถูกทำนายแล้ว มันจะส่งกลับคืนค่าเข้าไปใน pred
|
21 |
+
return 'Conversion Rate : '+str(pred) #function predict_cvr จะส่ง output ออกมาเป็น "Conversion Rate : pred"
|
22 |
+
|
23 |
+
xyz_campaign_id = gr.inputs.Dropdown(['campaign_a', 'campaign_b', 'campaign_c'], label="xyz_campaign_id")
|
24 |
+
gender = gr.inputs.Dropdown(['M', 'F'], label = "gender")
|
25 |
+
age = gr.inputs.Dropdown(['30-34', '35-39', '40-44', '45-49'], label = "age")
|
26 |
+
Impressions = gr.inputs.Slider(minimum=100,maximum=1000000,step=100,label = "Impressions")
|
27 |
+
Clicks = gr.inputs.Slider(minimum=1,maximum=500,step=1, label = "Clicks")
|
28 |
+
Total_Conversion = gr.inputs.Slider(minimum=1,maximum=100,step= 1, label = "Total_Conversion")
|
29 |
+
interest = gr.inputs.Slider(minimum=1,maximum=114,step= 1, label = "interest")
|
30 |
+
|
31 |
+
gr.Interface(predict_cvr, inputs =[xyz_campaign_id, gender, age, Impressions, Clicks,
|
32 |
+
Total_Conversion, interest],
|
33 |
+
outputs="label",
|
34 |
+
title = "Facebook Ads Conversions Prediction Web App",
|
35 |
+
theme = "dark-peach",
|
36 |
+
capture_session=True).launch(debug=True);
|