Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,432 @@
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
|
|
3 |
|
4 |
available_datasets = [
|
5 |
-
"
|
6 |
-
"
|
7 |
-
"
|
8 |
-
"
|
9 |
-
"
|
10 |
-
"
|
|
|
|
|
11 |
]
|
12 |
|
13 |
-
default_dataset = "
|
14 |
|
15 |
available_attributes = [
|
16 |
-
"Income",
|
17 |
"Age",
|
|
|
|
|
18 |
"Marital Status",
|
19 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
]
|
21 |
|
22 |
-
default_attributes = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
available_model_versions = ["Demographic Base"]
|
25 |
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
-
def generate_code_example(dataset, attributes, model_version):
|
29 |
-
attributes_with_types = ", ".join([f"fantix.type.{attr.upper().replace(' ', '_')}" for attr in attributes])
|
30 |
-
prediction_columns = ", ".join([f'"{attr}"' for attr in attributes])
|
31 |
-
|
32 |
code = f"""
|
33 |
import fantix
|
34 |
import pandas as pd
|
@@ -55,53 +453,716 @@ response = client.predict(
|
|
55 |
fantix.type.MARITAL_SATUS,
|
56 |
fantix.type.EDUCATION,
|
57 |
],
|
58 |
-
attribute_to_predict=[
|
59 |
-
|
|
|
|
|
60 |
)
|
61 |
"""
|
62 |
return code.strip()
|
63 |
|
64 |
-
def load_dataset(dataset, model_version):
|
65 |
-
return pd.DataFrame(
|
66 |
-
{
|
67 |
-
"Name": ["John", "Doe", "Jane", "Smith"],
|
68 |
-
"Age": [25, 30, 35, 40],
|
69 |
-
"Income": [50000, 60000, 70000, 80000],
|
70 |
-
"Marital Status": ["Single", "Married", "Single", "Married"],
|
71 |
-
"Education": ["High School", "Bachelor", "Master", "PhD"],
|
72 |
-
}
|
73 |
-
)
|
74 |
|
|
|
|
|
75 |
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
)
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
|
|
|
|
|
|
95 |
|
96 |
if access_token:
|
97 |
prediction_message, prediction_results = predict(
|
98 |
-
|
99 |
)
|
|
|
|
|
100 |
else:
|
101 |
prediction_message = "No access token provided, prediction skipped."
|
102 |
-
prediction_results = None
|
103 |
|
104 |
-
return loaded_data, prediction_message,
|
105 |
|
106 |
|
107 |
interface_theme = gr.themes.Default()
|
@@ -114,13 +1175,6 @@ with gr.Blocks(theme=interface_theme) as demo:
|
|
114 |
placeholder="Enter your access token here.",
|
115 |
)
|
116 |
|
117 |
-
gr.Markdown("### Model")
|
118 |
-
model_version = gr.Dropdown(
|
119 |
-
choices=available_model_versions,
|
120 |
-
label="Model Version",
|
121 |
-
value=default_model_version,
|
122 |
-
)
|
123 |
-
|
124 |
with gr.Row():
|
125 |
with gr.Column():
|
126 |
gr.Markdown("### Select Dataset and Attributes")
|
@@ -140,37 +1194,35 @@ with gr.Blocks(theme=interface_theme) as demo:
|
|
140 |
|
141 |
gr.Markdown("### Dataset Preview")
|
142 |
dataset_preview = gr.Dataframe()
|
|
|
143 |
|
144 |
with gr.Accordion("Code Example", open=False):
|
145 |
code_example = gr.Code(language="python")
|
146 |
-
|
147 |
-
predict_button = gr.Button("Predict Attributes")
|
148 |
|
149 |
-
gr.
|
150 |
-
prediction_preview = gr.Dataframe()
|
151 |
-
prediction_label = gr.Markdown("")
|
152 |
|
153 |
selected_dataset.change(
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
fn=generate_code_example,
|
155 |
-
inputs=[
|
156 |
outputs=code_example,
|
157 |
)
|
158 |
|
159 |
predict_button.click(
|
160 |
-
fn=
|
161 |
-
inputs=[selected_dataset, selected_attributes, access_token
|
162 |
-
outputs=[prediction_label,
|
163 |
-
)
|
164 |
-
predict_button.click(
|
165 |
-
fn=generate_code_example,
|
166 |
-
inputs=[selected_dataset, selected_attributes, model_version],
|
167 |
-
outputs=code_example,
|
168 |
)
|
169 |
|
170 |
demo.load(
|
171 |
fn=load_dataset_and_predict,
|
172 |
-
inputs=[selected_dataset, selected_attributes, access_token
|
173 |
-
outputs=[dataset_preview, prediction_label,
|
174 |
)
|
175 |
|
176 |
demo.launch()
|
|
|
1 |
+
# @title Define the application
|
2 |
+
|
3 |
+
import time
|
4 |
+
|
5 |
import gradio as gr
|
6 |
import pandas as pd
|
7 |
+
import requests
|
8 |
|
9 |
available_datasets = [
|
10 |
+
"Demographics",
|
11 |
+
"DoorDash Customer Segmentation",
|
12 |
+
"Personal Care and Lifestyle Category Propensity",
|
13 |
+
"Quick Service Restaurant (QSR) Propensity",
|
14 |
+
"Technology Brand Propensity",
|
15 |
+
"Uber Customer Segmentation",
|
16 |
+
"Walgreens Customer Segmentation",
|
17 |
+
"Walmart Customer Segmentation",
|
18 |
]
|
19 |
|
20 |
+
default_dataset = "Demographics"
|
21 |
|
22 |
available_attributes = [
|
|
|
23 |
"Age",
|
24 |
+
"Gender",
|
25 |
+
"Household Income",
|
26 |
"Marital Status",
|
27 |
+
"Occupation",
|
28 |
+
"Political Affiliation And Voting",
|
29 |
+
"Brand Propensity 365 Retail Markets",
|
30 |
+
"Brand Propensity 7 Eleven",
|
31 |
+
"Brand Propensity Affirm",
|
32 |
+
"Brand Propensity Afterpay",
|
33 |
+
"Brand Propensity Albert",
|
34 |
+
"Brand Propensity Amazon",
|
35 |
+
"Brand Propensity Amazon Prime Video",
|
36 |
+
"Brand Propensity Apple",
|
37 |
+
"Brand Propensity Bp",
|
38 |
+
"Brand Propensity Betmgm",
|
39 |
+
"Brand Propensity Brigit",
|
40 |
+
"Brand Propensity Burger King",
|
41 |
+
"Brand Propensity Cvs",
|
42 |
+
"Brand Propensity Chevron",
|
43 |
+
"Brand Propensity Chick Fil A",
|
44 |
+
"Brand Propensity Chumba Casino",
|
45 |
+
"Brand Propensity Circle K",
|
46 |
+
"Brand Propensity Cleo Ai",
|
47 |
+
"Brand Propensity Dave",
|
48 |
+
"Brand Propensity Dollar General",
|
49 |
+
"Brand Propensity Dollar Tree",
|
50 |
+
"Brand Propensity Doordash",
|
51 |
+
"Brand Propensity Draftkings",
|
52 |
+
"Brand Propensity Dunkin",
|
53 |
+
"Brand Propensity Earnin",
|
54 |
+
"Brand Propensity Empower",
|
55 |
+
"Brand Propensity Family Dollar",
|
56 |
+
"Brand Propensity Fanduel",
|
57 |
+
"Brand Propensity Fanduel Sportsbook",
|
58 |
+
"Brand Propensity Floatme",
|
59 |
+
"Brand Propensity Klarna",
|
60 |
+
"Brand Propensity Klover App",
|
61 |
+
"Brand Propensity Kroger",
|
62 |
+
"Brand Propensity Lyft",
|
63 |
+
"Brand Propensity Mcdonalds",
|
64 |
+
"Brand Propensity Moneylion",
|
65 |
+
"Brand Propensity Netflix",
|
66 |
+
"Brand Propensity Publix",
|
67 |
+
"Brand Propensity Quiktrip",
|
68 |
+
"Brand Propensity Sezzle",
|
69 |
+
"Brand Propensity Shell",
|
70 |
+
"Brand Propensity Sony Playstation",
|
71 |
+
"Brand Propensity Speedway",
|
72 |
+
"Brand Propensity Starbucks",
|
73 |
+
"Brand Propensity Sunoco",
|
74 |
+
"Brand Propensity T Mobile",
|
75 |
+
"Brand Propensity Taco Bell",
|
76 |
+
"Brand Propensity Target",
|
77 |
+
"Brand Propensity Uber",
|
78 |
+
"Brand Propensity Uber Eats",
|
79 |
+
"Brand Propensity Walgreens",
|
80 |
+
"Brand Propensity Walmart",
|
81 |
+
"Brand Propensity Wawa",
|
82 |
+
"Brand Propensity Wendys",
|
83 |
+
"Brand Propensity Zip Co",
|
84 |
+
"Recency 365 Retail Markets",
|
85 |
+
"Recency 7 Eleven",
|
86 |
+
"Recency Affirm",
|
87 |
+
"Recency Afterpay",
|
88 |
+
"Recency Albert",
|
89 |
+
"Recency Amazon",
|
90 |
+
"Recency Amazon Prime Video",
|
91 |
+
"Recency Apple",
|
92 |
+
"Recency Bp",
|
93 |
+
"Recency Betmgm",
|
94 |
+
"Recency Brigit",
|
95 |
+
"Recency Burger King",
|
96 |
+
"Recency Cvs",
|
97 |
+
"Recency Chevron",
|
98 |
+
"Recency Chick Fil A",
|
99 |
+
"Recency Chumba Casino",
|
100 |
+
"Recency Circle K",
|
101 |
+
"Recency Cleo Ai",
|
102 |
+
"Recency Dave",
|
103 |
+
"Recency Dollar General",
|
104 |
+
"Recency Dollar Tree",
|
105 |
+
"Recency Doordash",
|
106 |
+
"Recency Draftkings",
|
107 |
+
"Recency Dunkin",
|
108 |
+
"Recency Earnin",
|
109 |
+
"Recency Empower",
|
110 |
+
"Recency Family Dollar",
|
111 |
+
"Recency Fanduel",
|
112 |
+
"Recency Fanduel Sportsbook",
|
113 |
+
"Recency Floatme",
|
114 |
+
"Recency Klarna",
|
115 |
+
"Recency Klover App",
|
116 |
+
"Recency Kroger",
|
117 |
+
"Recency Lyft",
|
118 |
+
"Recency Mcdonalds",
|
119 |
+
"Recency Moneylion",
|
120 |
+
"Recency Netflix",
|
121 |
+
"Recency Publix",
|
122 |
+
"Recency Quiktrip",
|
123 |
+
"Recency Sezzle",
|
124 |
+
"Recency Shell",
|
125 |
+
"Recency Sony Playstation",
|
126 |
+
"Recency Speedway",
|
127 |
+
"Recency Starbucks",
|
128 |
+
"Recency Sunoco",
|
129 |
+
"Recency T Mobile",
|
130 |
+
"Recency Taco Bell",
|
131 |
+
"Recency Target",
|
132 |
+
"Recency Uber",
|
133 |
+
"Recency Uber Eats",
|
134 |
+
"Recency Walgreens",
|
135 |
+
"Recency Walmart",
|
136 |
+
"Recency Wawa",
|
137 |
+
"Recency Wendys",
|
138 |
+
"Recency Zip Co",
|
139 |
+
"Monetary 365 Retail Markets",
|
140 |
+
"Monetary 7 Eleven",
|
141 |
+
"Monetary Affirm",
|
142 |
+
"Monetary Afterpay",
|
143 |
+
"Monetary Albert",
|
144 |
+
"Monetary Amazon",
|
145 |
+
"Monetary Amazon Prime Video",
|
146 |
+
"Monetary Apple",
|
147 |
+
"Monetary Bp",
|
148 |
+
"Monetary Betmgm",
|
149 |
+
"Monetary Brigit",
|
150 |
+
"Monetary Burger King",
|
151 |
+
"Monetary Cvs",
|
152 |
+
"Monetary Chevron",
|
153 |
+
"Monetary Chick Fil A",
|
154 |
+
"Monetary Chumba Casino",
|
155 |
+
"Monetary Circle K",
|
156 |
+
"Monetary Cleo Ai",
|
157 |
+
"Monetary Dave",
|
158 |
+
"Monetary Dollar General",
|
159 |
+
"Monetary Dollar Tree",
|
160 |
+
"Monetary Doordash",
|
161 |
+
"Monetary Draftkings",
|
162 |
+
"Monetary Dunkin",
|
163 |
+
"Monetary Earnin",
|
164 |
+
"Monetary Empower",
|
165 |
+
"Monetary Family Dollar",
|
166 |
+
"Monetary Fanduel",
|
167 |
+
"Monetary Fanduel Sportsbook",
|
168 |
+
"Monetary Floatme",
|
169 |
+
"Monetary Klarna",
|
170 |
+
"Monetary Klover App",
|
171 |
+
"Monetary Kroger",
|
172 |
+
"Monetary Lyft",
|
173 |
+
"Monetary Mcdonalds",
|
174 |
+
"Monetary Moneylion",
|
175 |
+
"Monetary Netflix",
|
176 |
+
"Monetary Publix",
|
177 |
+
"Monetary Quiktrip",
|
178 |
+
"Monetary Sezzle",
|
179 |
+
"Monetary Shell",
|
180 |
+
"Monetary Sony Playstation",
|
181 |
+
"Monetary Speedway",
|
182 |
+
"Monetary Starbucks",
|
183 |
+
"Monetary Sunoco",
|
184 |
+
"Monetary T Mobile",
|
185 |
+
"Monetary Taco Bell",
|
186 |
+
"Monetary Target",
|
187 |
+
"Monetary Uber",
|
188 |
+
"Monetary Uber Eats",
|
189 |
+
"Monetary Walgreens",
|
190 |
+
"Monetary Walmart",
|
191 |
+
"Monetary Wawa",
|
192 |
+
"Monetary Wendys",
|
193 |
+
"Monetary Zip Co",
|
194 |
+
"Frequency 365 Retail Markets",
|
195 |
+
"Frequency 7 Eleven",
|
196 |
+
"Frequency Affirm",
|
197 |
+
"Frequency Afterpay",
|
198 |
+
"Frequency Albert",
|
199 |
+
"Frequency Amazon",
|
200 |
+
"Frequency Amazon Prime Video",
|
201 |
+
"Frequency Apple",
|
202 |
+
"Frequency Bp",
|
203 |
+
"Frequency Betmgm",
|
204 |
+
"Frequency Brigit",
|
205 |
+
"Frequency Burger King",
|
206 |
+
"Frequency Cvs",
|
207 |
+
"Frequency Chevron",
|
208 |
+
"Frequency Chick Fil A",
|
209 |
+
"Frequency Chumba Casino",
|
210 |
+
"Frequency Circle K",
|
211 |
+
"Frequency Cleo Ai",
|
212 |
+
"Frequency Dave",
|
213 |
+
"Frequency Dollar General",
|
214 |
+
"Frequency Dollar Tree",
|
215 |
+
"Frequency Doordash",
|
216 |
+
"Frequency Draftkings",
|
217 |
+
"Frequency Dunkin",
|
218 |
+
"Frequency Earnin",
|
219 |
+
"Frequency Empower",
|
220 |
+
"Frequency Family Dollar",
|
221 |
+
"Frequency Fanduel",
|
222 |
+
"Frequency Fanduel Sportsbook",
|
223 |
+
"Frequency Floatme",
|
224 |
+
"Frequency Klarna",
|
225 |
+
"Frequency Klover App",
|
226 |
+
"Frequency Kroger",
|
227 |
+
"Frequency Lyft",
|
228 |
+
"Frequency Mcdonalds",
|
229 |
+
"Frequency Moneylion",
|
230 |
+
"Frequency Netflix",
|
231 |
+
"Frequency Publix",
|
232 |
+
"Frequency Quiktrip",
|
233 |
+
"Frequency Sezzle",
|
234 |
+
"Frequency Shell",
|
235 |
+
"Frequency Sony Playstation",
|
236 |
+
"Frequency Speedway",
|
237 |
+
"Frequency Starbucks",
|
238 |
+
"Frequency Sunoco",
|
239 |
+
"Frequency T Mobile",
|
240 |
+
"Frequency Taco Bell",
|
241 |
+
"Frequency Target",
|
242 |
+
"Frequency Uber",
|
243 |
+
"Frequency Uber Eats",
|
244 |
+
"Frequency Walgreens",
|
245 |
+
"Frequency Walmart",
|
246 |
+
"Frequency Wawa",
|
247 |
+
"Frequency Wendys",
|
248 |
+
"Frequency Zip Co",
|
249 |
+
"Category Propensity Atm",
|
250 |
+
"Category Propensity Airlines And Aviation Services",
|
251 |
+
"Category Propensity Arts And Crafts",
|
252 |
+
"Category Propensity Arts And Entertainment",
|
253 |
+
"Category Propensity Automotive",
|
254 |
+
"Category Propensity Beauty Products",
|
255 |
+
"Category Propensity Billpay",
|
256 |
+
"Category Propensity Bookstores",
|
257 |
+
"Category Propensity Business Services",
|
258 |
+
"Category Propensity Car Service",
|
259 |
+
"Category Propensity Clothing And Accessories",
|
260 |
+
"Category Propensity Computers And Electronics",
|
261 |
+
"Category Propensity Convenience Stores",
|
262 |
+
"Category Propensity Credit",
|
263 |
+
"Category Propensity Credit Card",
|
264 |
+
"Category Propensity Debit",
|
265 |
+
"Category Propensity Department Stores",
|
266 |
+
"Category Propensity Deposit",
|
267 |
+
"Category Propensity Digital Purchase",
|
268 |
+
"Category Propensity Discount Stores",
|
269 |
+
"Category Propensity Education",
|
270 |
+
"Category Propensity Entertainment",
|
271 |
+
"Category Propensity Financial",
|
272 |
+
"Category Propensity Food And Beverage",
|
273 |
+
"Category Propensity Food And Beverage Store",
|
274 |
+
"Category Propensity Gas Stations",
|
275 |
+
"Category Propensity Gift And Novelty",
|
276 |
+
"Category Propensity Government Departments And Agencies",
|
277 |
+
"Category Propensity Gyms And Fitness Centers",
|
278 |
+
"Category Propensity Healthcare Services",
|
279 |
+
"Category Propensity Insufficient Funds",
|
280 |
+
"Category Propensity Insurance",
|
281 |
+
"Category Propensity Jewelry And Watches",
|
282 |
+
"Category Propensity Keep The Change Savings Program",
|
283 |
+
"Category Propensity Lodging",
|
284 |
+
"Category Propensity Organizations And Associations",
|
285 |
+
"Category Propensity Overdraft",
|
286 |
+
"Category Propensity Parking",
|
287 |
+
"Category Propensity Personal Care",
|
288 |
+
"Category Propensity Pharmacies",
|
289 |
+
"Category Propensity Public Transportation Services",
|
290 |
+
"Category Propensity Religious",
|
291 |
+
"Category Propensity Rent",
|
292 |
+
"Category Propensity Restaurants",
|
293 |
+
"Category Propensity Shipping And Freight",
|
294 |
+
"Category Propensity Sporting Goods",
|
295 |
+
"Category Propensity Subscription",
|
296 |
+
"Category Propensity Supermarkets And Groceries",
|
297 |
+
"Category Propensity Taxi",
|
298 |
+
"Category Propensity Telecommunication Services",
|
299 |
+
"Category Propensity Third Party",
|
300 |
+
"Category Propensity Utilities",
|
301 |
+
"Category Propensity Withdrawal",
|
302 |
+
"LTV 365 Retail Markets",
|
303 |
+
"LTV 7 Eleven",
|
304 |
+
"LTV Affirm",
|
305 |
+
"LTV Afterpay",
|
306 |
+
"LTV Albert",
|
307 |
+
"LTV Amazon",
|
308 |
+
"LTV Amazon Prime Video",
|
309 |
+
"LTV Apple",
|
310 |
+
"LTV Bp",
|
311 |
+
"LTV Betmgm",
|
312 |
+
"LTV Brigit",
|
313 |
+
"LTV Burger King",
|
314 |
+
"LTV Cvs",
|
315 |
+
"LTV Chevron",
|
316 |
+
"LTV Chick Fil A",
|
317 |
+
"LTV Chumba Casino",
|
318 |
+
"LTV Circle K",
|
319 |
+
"LTV Cleo Ai",
|
320 |
+
"LTV Dave",
|
321 |
+
"LTV Dollar General",
|
322 |
+
"LTV Dollar Tree",
|
323 |
+
"LTV Doordash",
|
324 |
+
"LTV Draftkings",
|
325 |
+
"LTV Dunkin",
|
326 |
+
"LTV Earnin",
|
327 |
+
"LTV Empower",
|
328 |
+
"LTV Family Dollar",
|
329 |
+
"LTV Fanduel",
|
330 |
+
"LTV Fanduel Sportsbook",
|
331 |
+
"LTV Floatme",
|
332 |
+
"LTV Klarna",
|
333 |
+
"LTV Klover App",
|
334 |
+
"LTV Kroger",
|
335 |
+
"LTV Lyft",
|
336 |
+
"LTV Mcdonalds",
|
337 |
+
"LTV Moneylion",
|
338 |
+
"LTV Netflix",
|
339 |
+
"LTV Publix",
|
340 |
+
"LTV Quiktrip",
|
341 |
+
"LTV Sezzle",
|
342 |
+
"LTV Shell",
|
343 |
+
"LTV Sony Playstation",
|
344 |
+
"LTV Speedway",
|
345 |
+
"LTV Starbucks",
|
346 |
+
"LTV Sunoco",
|
347 |
+
"LTV T Mobile",
|
348 |
+
"LTV Taco Bell",
|
349 |
+
"LTV Target",
|
350 |
+
"LTV Uber",
|
351 |
+
"LTV Uber Eats",
|
352 |
+
"LTV Walgreens",
|
353 |
+
"LTV Walmart",
|
354 |
+
"LTV Wawa",
|
355 |
+
"LTV Wendys",
|
356 |
+
"LTV Zip Co",
|
357 |
+
"Share Wallet 365 Retail Markets",
|
358 |
+
"Share Wallet 7 Eleven",
|
359 |
+
"Share Wallet Affirm",
|
360 |
+
"Share Wallet Afterpay",
|
361 |
+
"Share Wallet Albert",
|
362 |
+
"Share Wallet Amazon",
|
363 |
+
"Share Wallet Amazon Prime Video",
|
364 |
+
"Share Wallet Apple",
|
365 |
+
"Share Wallet Bp",
|
366 |
+
"Share Wallet Betmgm",
|
367 |
+
"Share Wallet Brigit",
|
368 |
+
"Share Wallet Burger King",
|
369 |
+
"Share Wallet Cvs",
|
370 |
+
"Share Wallet Chevron",
|
371 |
+
"Share Wallet Chick Fil A",
|
372 |
+
"Share Wallet Chumba Casino",
|
373 |
+
"Share Wallet Circle K",
|
374 |
+
"Share Wallet Cleo Ai",
|
375 |
+
"Share Wallet Dave",
|
376 |
+
"Share Wallet Dollar General",
|
377 |
+
"Share Wallet Dollar Tree",
|
378 |
+
"Share Wallet Doordash",
|
379 |
+
"Share Wallet Draftkings",
|
380 |
+
"Share Wallet Dunkin",
|
381 |
+
"Share Wallet Earnin",
|
382 |
+
"Share Wallet Empower",
|
383 |
+
"Share Wallet Family Dollar",
|
384 |
+
"Share Wallet Fanduel",
|
385 |
+
"Share Wallet Fanduel Sportsbook",
|
386 |
+
"Share Wallet Floatme",
|
387 |
+
"Share Wallet Klarna",
|
388 |
+
"Share Wallet Klover App",
|
389 |
+
"Share Wallet Kroger",
|
390 |
+
"Share Wallet Lyft",
|
391 |
+
"Share Wallet Mcdonalds",
|
392 |
+
"Share Wallet Moneylion",
|
393 |
+
"Share Wallet Netflix",
|
394 |
+
"Share Wallet Publix",
|
395 |
+
"Share Wallet Quiktrip",
|
396 |
+
"Share Wallet Sezzle",
|
397 |
+
"Share Wallet Shell",
|
398 |
+
"Share Wallet Sony Playstation",
|
399 |
+
"Share Wallet Speedway",
|
400 |
+
"Share Wallet Starbucks",
|
401 |
+
"Share Wallet Sunoco",
|
402 |
+
"Share Wallet T Mobile",
|
403 |
+
"Share Wallet Taco Bell",
|
404 |
+
"Share Wallet Target",
|
405 |
+
"Share Wallet Uber",
|
406 |
+
"Share Wallet Uber Eats",
|
407 |
+
"Share Wallet Walgreens",
|
408 |
+
"Share Wallet Walmart",
|
409 |
+
"Share Wallet Wawa",
|
410 |
+
"Share Wallet Wendys",
|
411 |
+
"Share Wallet Zip Co",
|
412 |
]
|
413 |
|
414 |
+
default_attributes = [
|
415 |
+
"Brand Propensity 365 Retail Markets",
|
416 |
+
"Brand Propensity 7 Eleven",
|
417 |
+
"Brand Propensity Affirm",
|
418 |
+
"Brand Propensity Afterpay",
|
419 |
+
"Brand Propensity Albert",
|
420 |
+
"Brand Propensity Amazon",
|
421 |
+
"Brand Propensity Amazon Prime Video",
|
422 |
+
]
|
423 |
|
|
|
424 |
|
425 |
+
def generate_code_example(attributes):
|
426 |
+
attributes_with_types = ", \n".join(
|
427 |
+
[f"\t\tfantix.type.{attr.upper().replace(' ', '_')}" for attr in attributes]
|
428 |
+
)
|
429 |
|
|
|
|
|
|
|
|
|
430 |
code = f"""
|
431 |
import fantix
|
432 |
import pandas as pd
|
|
|
453 |
fantix.type.MARITAL_SATUS,
|
454 |
fantix.type.EDUCATION,
|
455 |
],
|
456 |
+
attribute_to_predict=[
|
457 |
+
{attributes_with_types}
|
458 |
+
],
|
459 |
+
model_version="demographic-33k-alpha",
|
460 |
)
|
461 |
"""
|
462 |
return code.strip()
|
463 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
464 |
|
465 |
+
def load_dataset(dataset):
|
466 |
+
formated_dataset_name = dataset.lower().replace(" ", "_")
|
467 |
|
468 |
+
print(f"Loading dataset: {formated_dataset_name}")
|
469 |
+
|
470 |
+
if formated_dataset_name == "demographics":
|
471 |
+
return pd.DataFrame(
|
472 |
+
{
|
473 |
+
"age": [
|
474 |
+
"65-74",
|
475 |
+
"25-34",
|
476 |
+
"65-74",
|
477 |
+
"65-74",
|
478 |
+
"65-74",
|
479 |
+
"75+",
|
480 |
+
"55-64",
|
481 |
+
"75+",
|
482 |
+
"65-74",
|
483 |
+
"25-34",
|
484 |
+
"25-34",
|
485 |
+
"75+",
|
486 |
+
"55-64",
|
487 |
+
"65-74",
|
488 |
+
"65-74",
|
489 |
+
"75+",
|
490 |
+
"75+",
|
491 |
+
"55-64",
|
492 |
+
"35-44",
|
493 |
+
],
|
494 |
+
"gender": [
|
495 |
+
"female",
|
496 |
+
"male",
|
497 |
+
"female",
|
498 |
+
"female",
|
499 |
+
"female",
|
500 |
+
"female",
|
501 |
+
"male",
|
502 |
+
"female",
|
503 |
+
"male",
|
504 |
+
"female",
|
505 |
+
"female",
|
506 |
+
"female",
|
507 |
+
"male",
|
508 |
+
"female",
|
509 |
+
"male",
|
510 |
+
"male",
|
511 |
+
"female",
|
512 |
+
"female",
|
513 |
+
"male",
|
514 |
+
],
|
515 |
+
"occupation": [
|
516 |
+
"professional_or_technical",
|
517 |
+
"business_owner",
|
518 |
+
"management",
|
519 |
+
"management",
|
520 |
+
"clerical_service_worker",
|
521 |
+
"retired",
|
522 |
+
"business_owner",
|
523 |
+
"management",
|
524 |
+
"business_owner",
|
525 |
+
"business_owner",
|
526 |
+
"management",
|
527 |
+
"professional_or_technical",
|
528 |
+
"management",
|
529 |
+
"business_owner",
|
530 |
+
"contractors",
|
531 |
+
"retired",
|
532 |
+
"professional_or_technical",
|
533 |
+
"business_owner",
|
534 |
+
"contractors",
|
535 |
+
],
|
536 |
+
"household_income": [
|
537 |
+
"$75k-$99k",
|
538 |
+
"$100k-$149k",
|
539 |
+
"$30k-$39k",
|
540 |
+
"$75k-$99k",
|
541 |
+
"$20k-$29k",
|
542 |
+
"$30k-$39k",
|
543 |
+
"$20k-$29k",
|
544 |
+
"$75k-$99k",
|
545 |
+
"$40k-$49k",
|
546 |
+
"$100k-$149k",
|
547 |
+
"$100k-$149k",
|
548 |
+
"$100k-$149k",
|
549 |
+
"$100k-$149k",
|
550 |
+
"$50k-$74k",
|
551 |
+
"$30k-$39k",
|
552 |
+
"$40k-$49k",
|
553 |
+
"$50k-$74k",
|
554 |
+
"$100k-$149k",
|
555 |
+
"$20k-$29k",
|
556 |
+
],
|
557 |
+
}
|
558 |
+
)
|
559 |
+
elif formated_dataset_name == "doordash_customer_segmentation":
|
560 |
+
return pd.DataFrame(
|
561 |
+
{
|
562 |
+
"monetary_doordash": [
|
563 |
+
1,
|
564 |
+
3,
|
565 |
+
2,
|
566 |
+
2,
|
567 |
+
1,
|
568 |
+
1,
|
569 |
+
1,
|
570 |
+
2,
|
571 |
+
4,
|
572 |
+
4,
|
573 |
+
2,
|
574 |
+
2,
|
575 |
+
2,
|
576 |
+
1,
|
577 |
+
1,
|
578 |
+
4,
|
579 |
+
4,
|
580 |
+
1,
|
581 |
+
1,
|
582 |
+
],
|
583 |
+
"frequency_doordash": [
|
584 |
+
1,
|
585 |
+
1,
|
586 |
+
1,
|
587 |
+
1,
|
588 |
+
1,
|
589 |
+
1,
|
590 |
+
1,
|
591 |
+
1,
|
592 |
+
1,
|
593 |
+
1,
|
594 |
+
1,
|
595 |
+
1,
|
596 |
+
1,
|
597 |
+
1,
|
598 |
+
1,
|
599 |
+
4,
|
600 |
+
4,
|
601 |
+
1,
|
602 |
+
1,
|
603 |
+
],
|
604 |
+
"recency_doorDash": [
|
605 |
+
4,
|
606 |
+
1,
|
607 |
+
3,
|
608 |
+
3,
|
609 |
+
2,
|
610 |
+
1,
|
611 |
+
3,
|
612 |
+
5,
|
613 |
+
5,
|
614 |
+
5,
|
615 |
+
5,
|
616 |
+
5,
|
617 |
+
5,
|
618 |
+
4,
|
619 |
+
1,
|
620 |
+
1,
|
621 |
+
1,
|
622 |
+
2,
|
623 |
+
2,
|
624 |
+
],
|
625 |
+
}
|
626 |
+
)
|
627 |
+
elif formated_dataset_name == "personal_care_and_lifestyle_category_propensity":
|
628 |
+
return pd.DataFrame(
|
629 |
+
{
|
630 |
+
"category_propensity_beauty_products": [
|
631 |
+
3,
|
632 |
+
3,
|
633 |
+
1,
|
634 |
+
1,
|
635 |
+
1,
|
636 |
+
1,
|
637 |
+
1,
|
638 |
+
1,
|
639 |
+
1,
|
640 |
+
1,
|
641 |
+
1,
|
642 |
+
1,
|
643 |
+
1,
|
644 |
+
1,
|
645 |
+
1,
|
646 |
+
1,
|
647 |
+
2,
|
648 |
+
2,
|
649 |
+
2,
|
650 |
+
],
|
651 |
+
"category_propensity_personal_care": [
|
652 |
+
2,
|
653 |
+
2,
|
654 |
+
2,
|
655 |
+
2,
|
656 |
+
2,
|
657 |
+
2,
|
658 |
+
2,
|
659 |
+
2,
|
660 |
+
1,
|
661 |
+
1,
|
662 |
+
1,
|
663 |
+
1,
|
664 |
+
1,
|
665 |
+
1,
|
666 |
+
1,
|
667 |
+
1,
|
668 |
+
2,
|
669 |
+
2,
|
670 |
+
2,
|
671 |
+
],
|
672 |
+
"category_propensity_gyms_and_fitness_centers": [
|
673 |
+
3,
|
674 |
+
3,
|
675 |
+
1,
|
676 |
+
1,
|
677 |
+
1,
|
678 |
+
1,
|
679 |
+
1,
|
680 |
+
1,
|
681 |
+
1,
|
682 |
+
1,
|
683 |
+
1,
|
684 |
+
1,
|
685 |
+
1,
|
686 |
+
1,
|
687 |
+
1,
|
688 |
+
1,
|
689 |
+
1,
|
690 |
+
1,
|
691 |
+
1,
|
692 |
+
],
|
693 |
+
"category_propensity_pharmacies": [
|
694 |
+
4,
|
695 |
+
4,
|
696 |
+
1,
|
697 |
+
1,
|
698 |
+
1,
|
699 |
+
1,
|
700 |
+
1,
|
701 |
+
1,
|
702 |
+
1,
|
703 |
+
1,
|
704 |
+
1,
|
705 |
+
1,
|
706 |
+
1,
|
707 |
+
1,
|
708 |
+
1,
|
709 |
+
1,
|
710 |
+
4,
|
711 |
+
4,
|
712 |
+
4,
|
713 |
+
],
|
714 |
+
}
|
715 |
)
|
716 |
|
717 |
+
elif formated_dataset_name == "quick_service_restaurant_(qsr)_propensity":
|
718 |
+
return pd.DataFrame(
|
719 |
+
{
|
720 |
+
"brand_propensity_burger_king": [
|
721 |
+
2,
|
722 |
+
2,
|
723 |
+
2,
|
724 |
+
2,
|
725 |
+
2,
|
726 |
+
2,
|
727 |
+
1,
|
728 |
+
1,
|
729 |
+
1,
|
730 |
+
1,
|
731 |
+
1,
|
732 |
+
1,
|
733 |
+
3,
|
734 |
+
3,
|
735 |
+
3,
|
736 |
+
3,
|
737 |
+
1,
|
738 |
+
1,
|
739 |
+
1,
|
740 |
+
],
|
741 |
+
"brand_propensity_chick_fil_a": [
|
742 |
+
1,
|
743 |
+
1,
|
744 |
+
1,
|
745 |
+
1,
|
746 |
+
1,
|
747 |
+
1,
|
748 |
+
1,
|
749 |
+
1,
|
750 |
+
1,
|
751 |
+
1,
|
752 |
+
1,
|
753 |
+
1,
|
754 |
+
2,
|
755 |
+
2,
|
756 |
+
2,
|
757 |
+
2,
|
758 |
+
4,
|
759 |
+
5,
|
760 |
+
5,
|
761 |
+
],
|
762 |
+
"brand_propensity_mcdonalds": [
|
763 |
+
2,
|
764 |
+
2,
|
765 |
+
2,
|
766 |
+
2,
|
767 |
+
2,
|
768 |
+
2,
|
769 |
+
1,
|
770 |
+
1,
|
771 |
+
1,
|
772 |
+
1,
|
773 |
+
1,
|
774 |
+
1,
|
775 |
+
2,
|
776 |
+
2,
|
777 |
+
2,
|
778 |
+
2,
|
779 |
+
1,
|
780 |
+
4,
|
781 |
+
4,
|
782 |
+
],
|
783 |
+
"brand_propensity_taco_bell": [
|
784 |
+
2,
|
785 |
+
2,
|
786 |
+
2,
|
787 |
+
2,
|
788 |
+
2,
|
789 |
+
2,
|
790 |
+
1,
|
791 |
+
1,
|
792 |
+
1,
|
793 |
+
1,
|
794 |
+
1,
|
795 |
+
1,
|
796 |
+
5,
|
797 |
+
5,
|
798 |
+
5,
|
799 |
+
5,
|
800 |
+
2,
|
801 |
+
1,
|
802 |
+
1,
|
803 |
+
],
|
804 |
+
}
|
805 |
+
)
|
806 |
+
|
807 |
+
elif formated_dataset_name == "technology_brand_propensity":
|
808 |
+
return pd.DataFrame(
|
809 |
+
{
|
810 |
+
"brand_propensity_apple": [
|
811 |
+
4,
|
812 |
+
4,
|
813 |
+
4,
|
814 |
+
2,
|
815 |
+
2,
|
816 |
+
2,
|
817 |
+
2,
|
818 |
+
2,
|
819 |
+
2,
|
820 |
+
5,
|
821 |
+
5,
|
822 |
+
5,
|
823 |
+
5,
|
824 |
+
5,
|
825 |
+
5,
|
826 |
+
5,
|
827 |
+
5,
|
828 |
+
2,
|
829 |
+
2,
|
830 |
+
],
|
831 |
+
"brand_propensity_amazon": [
|
832 |
+
2,
|
833 |
+
2,
|
834 |
+
2,
|
835 |
+
1,
|
836 |
+
1,
|
837 |
+
1,
|
838 |
+
1,
|
839 |
+
1,
|
840 |
+
1,
|
841 |
+
2,
|
842 |
+
2,
|
843 |
+
2,
|
844 |
+
2,
|
845 |
+
2,
|
846 |
+
2,
|
847 |
+
2,
|
848 |
+
2,
|
849 |
+
1,
|
850 |
+
1,
|
851 |
+
],
|
852 |
+
"brand_propensity_sony_playstation": [
|
853 |
+
2,
|
854 |
+
2,
|
855 |
+
2,
|
856 |
+
3,
|
857 |
+
3,
|
858 |
+
3,
|
859 |
+
3,
|
860 |
+
3,
|
861 |
+
5,
|
862 |
+
2,
|
863 |
+
2,
|
864 |
+
2,
|
865 |
+
2,
|
866 |
+
2,
|
867 |
+
2,
|
868 |
+
2,
|
869 |
+
2,
|
870 |
+
1,
|
871 |
+
1,
|
872 |
+
],
|
873 |
+
"brand_propensity_netflix": [
|
874 |
+
2,
|
875 |
+
2,
|
876 |
+
2,
|
877 |
+
3,
|
878 |
+
3,
|
879 |
+
3,
|
880 |
+
3,
|
881 |
+
3,
|
882 |
+
2,
|
883 |
+
2,
|
884 |
+
2,
|
885 |
+
2,
|
886 |
+
2,
|
887 |
+
2,
|
888 |
+
2,
|
889 |
+
2,
|
890 |
+
2,
|
891 |
+
2,
|
892 |
+
2,
|
893 |
+
],
|
894 |
+
}
|
895 |
+
)
|
896 |
+
elif formated_dataset_name == "uber_customer_segmentation":
|
897 |
+
return pd.DataFrame(
|
898 |
+
{
|
899 |
+
"monetary_uber": [
|
900 |
+
2,
|
901 |
+
2,
|
902 |
+
5,
|
903 |
+
1,
|
904 |
+
1,
|
905 |
+
1,
|
906 |
+
1,
|
907 |
+
1,
|
908 |
+
1,
|
909 |
+
1,
|
910 |
+
1,
|
911 |
+
1,
|
912 |
+
1,
|
913 |
+
1,
|
914 |
+
1,
|
915 |
+
1,
|
916 |
+
1,
|
917 |
+
1,
|
918 |
+
2,
|
919 |
+
],
|
920 |
+
"frequency_uber": [
|
921 |
+
2,
|
922 |
+
2,
|
923 |
+
5,
|
924 |
+
1,
|
925 |
+
1,
|
926 |
+
1,
|
927 |
+
1,
|
928 |
+
1,
|
929 |
+
1,
|
930 |
+
1,
|
931 |
+
1,
|
932 |
+
1,
|
933 |
+
1,
|
934 |
+
1,
|
935 |
+
1,
|
936 |
+
1,
|
937 |
+
1,
|
938 |
+
1,
|
939 |
+
2,
|
940 |
+
],
|
941 |
+
"recency_uber": [
|
942 |
+
5,
|
943 |
+
5,
|
944 |
+
1,
|
945 |
+
4,
|
946 |
+
1,
|
947 |
+
4,
|
948 |
+
1,
|
949 |
+
1,
|
950 |
+
5,
|
951 |
+
5,
|
952 |
+
3,
|
953 |
+
3,
|
954 |
+
3,
|
955 |
+
2,
|
956 |
+
3,
|
957 |
+
2,
|
958 |
+
3,
|
959 |
+
1,
|
960 |
+
4,
|
961 |
+
],
|
962 |
+
}
|
963 |
+
)
|
964 |
+
elif formated_dataset_name == "walgreens_customer_segmentation":
|
965 |
+
return pd.DataFrame(
|
966 |
+
{
|
967 |
+
"monetary_walgreens": [
|
968 |
+
4,
|
969 |
+
3,
|
970 |
+
2,
|
971 |
+
2,
|
972 |
+
3,
|
973 |
+
3,
|
974 |
+
1,
|
975 |
+
2,
|
976 |
+
1,
|
977 |
+
1,
|
978 |
+
2,
|
979 |
+
2,
|
980 |
+
2,
|
981 |
+
2,
|
982 |
+
2,
|
983 |
+
2,
|
984 |
+
2,
|
985 |
+
2,
|
986 |
+
1,
|
987 |
+
],
|
988 |
+
"frequency_walgreens": [
|
989 |
+
4,
|
990 |
+
2,
|
991 |
+
1,
|
992 |
+
1,
|
993 |
+
1,
|
994 |
+
1,
|
995 |
+
1,
|
996 |
+
1,
|
997 |
+
1,
|
998 |
+
1,
|
999 |
+
2,
|
1000 |
+
1,
|
1001 |
+
1,
|
1002 |
+
5,
|
1003 |
+
5,
|
1004 |
+
5,
|
1005 |
+
5,
|
1006 |
+
5,
|
1007 |
+
1,
|
1008 |
+
],
|
1009 |
+
"recency_walgreens": [
|
1010 |
+
1,
|
1011 |
+
4,
|
1012 |
+
4,
|
1013 |
+
4,
|
1014 |
+
5,
|
1015 |
+
5,
|
1016 |
+
5,
|
1017 |
+
1,
|
1018 |
+
4,
|
1019 |
+
4,
|
1020 |
+
1,
|
1021 |
+
3,
|
1022 |
+
3,
|
1023 |
+
1,
|
1024 |
+
1,
|
1025 |
+
1,
|
1026 |
+
1,
|
1027 |
+
1,
|
1028 |
+
4,
|
1029 |
+
],
|
1030 |
+
}
|
1031 |
+
)
|
1032 |
+
elif formated_dataset_name == "walmart_customer_segmentation":
|
1033 |
+
return pd.DataFrame(
|
1034 |
+
{
|
1035 |
+
"monetary_walmart": [
|
1036 |
+
1,
|
1037 |
+
1,
|
1038 |
+
1,
|
1039 |
+
3,
|
1040 |
+
3,
|
1041 |
+
1,
|
1042 |
+
1,
|
1043 |
+
1,
|
1044 |
+
1,
|
1045 |
+
1,
|
1046 |
+
1,
|
1047 |
+
1,
|
1048 |
+
1,
|
1049 |
+
1,
|
1050 |
+
1,
|
1051 |
+
1,
|
1052 |
+
1,
|
1053 |
+
1,
|
1054 |
+
1,
|
1055 |
+
],
|
1056 |
+
"frequency_walmart": [
|
1057 |
+
1,
|
1058 |
+
1,
|
1059 |
+
1,
|
1060 |
+
1,
|
1061 |
+
1,
|
1062 |
+
2,
|
1063 |
+
2,
|
1064 |
+
1,
|
1065 |
+
1,
|
1066 |
+
1,
|
1067 |
+
1,
|
1068 |
+
1,
|
1069 |
+
1,
|
1070 |
+
1,
|
1071 |
+
1,
|
1072 |
+
1,
|
1073 |
+
1,
|
1074 |
+
1,
|
1075 |
+
1,
|
1076 |
+
],
|
1077 |
+
"recency_walmart": [
|
1078 |
+
1,
|
1079 |
+
1,
|
1080 |
+
1,
|
1081 |
+
3,
|
1082 |
+
2,
|
1083 |
+
2,
|
1084 |
+
2,
|
1085 |
+
1,
|
1086 |
+
3,
|
1087 |
+
3,
|
1088 |
+
3,
|
1089 |
+
5,
|
1090 |
+
5,
|
1091 |
+
5,
|
1092 |
+
5,
|
1093 |
+
5,
|
1094 |
+
4,
|
1095 |
+
1,
|
1096 |
+
2,
|
1097 |
+
],
|
1098 |
+
}
|
1099 |
+
)
|
1100 |
+
else:
|
1101 |
+
return pd.DataFrame()
|
1102 |
+
|
1103 |
+
|
1104 |
+
def predict(dataset, attributes, access_token):
|
1105 |
+
"""
|
1106 |
+
Makes a prediction using an external API call and calculates the performance.
|
1107 |
+
|
1108 |
+
Parameters:
|
1109 |
+
- dataset (list of dict): The input data for prediction.
|
1110 |
+
- attributes (list): The attributes to predict.
|
1111 |
+
- access_token (str): The access token for API authentication.
|
1112 |
+
|
1113 |
+
Returns:
|
1114 |
+
- tuple: A message about the prediction, prediction results as a DataFrame,
|
1115 |
+
and the number of predictions made in the given time frame.
|
1116 |
+
"""
|
1117 |
+
api_url = "https://rb3mw988lz88cvpz.us-east-1.aws.endpoints.huggingface.cloud"
|
1118 |
+
headers = {
|
1119 |
+
"Accept": "application/json",
|
1120 |
+
"Authorization": f"Bearer {access_token}",
|
1121 |
+
"Content-Type": "application/json"
|
1122 |
+
}
|
1123 |
+
|
1124 |
+
payload = {
|
1125 |
+
"inputs": [
|
1126 |
+
{
|
1127 |
+
"input_data": dataset.to_dict(orient="records"),
|
1128 |
+
"attributes_to_predict": [
|
1129 |
+
attribute.lower().replace(" ", "_") for attribute in attributes
|
1130 |
+
],
|
1131 |
+
}
|
1132 |
+
],
|
1133 |
+
}
|
1134 |
+
|
1135 |
+
start_time = time.time()
|
1136 |
+
response = requests.post(api_url, headers=headers, json=payload)
|
1137 |
+
end_time = time.time()
|
1138 |
|
1139 |
+
elapsed_time = end_time - start_time
|
1140 |
+
|
1141 |
+
if response.status_code == 200:
|
1142 |
+
prediction_results = pd.DataFrame(response.json())
|
1143 |
+
predictions_count = len(prediction_results)
|
1144 |
+
prediction_message = f"{predictions_count} predictions made in {elapsed_time:.2f} seconds."
|
1145 |
+
else:
|
1146 |
+
prediction_message = "Failed to make predictions."
|
1147 |
+
prediction_results = pd.DataFrame([])
|
1148 |
|
1149 |
+
return prediction_message, prediction_results
|
1150 |
+
|
1151 |
+
def load_dataset_and_predict(dataset, attributes, access_token):
|
1152 |
+
loaded_data = load_dataset(dataset)
|
1153 |
+
|
1154 |
+
code_example = generate_code_example(attributes)
|
1155 |
|
1156 |
if access_token:
|
1157 |
prediction_message, prediction_results = predict(
|
1158 |
+
loaded_data, attributes, access_token
|
1159 |
)
|
1160 |
+
|
1161 |
+
return prediction_results, prediction_message, code_example
|
1162 |
else:
|
1163 |
prediction_message = "No access token provided, prediction skipped."
|
|
|
1164 |
|
1165 |
+
return loaded_data, prediction_message, code_example
|
1166 |
|
1167 |
|
1168 |
interface_theme = gr.themes.Default()
|
|
|
1175 |
placeholder="Enter your access token here.",
|
1176 |
)
|
1177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1178 |
with gr.Row():
|
1179 |
with gr.Column():
|
1180 |
gr.Markdown("### Select Dataset and Attributes")
|
|
|
1194 |
|
1195 |
gr.Markdown("### Dataset Preview")
|
1196 |
dataset_preview = gr.Dataframe()
|
1197 |
+
prediction_label = gr.Markdown("")
|
1198 |
|
1199 |
with gr.Accordion("Code Example", open=False):
|
1200 |
code_example = gr.Code(language="python")
|
|
|
|
|
1201 |
|
1202 |
+
predict_button = gr.Button("Predict Attributes")
|
|
|
|
|
1203 |
|
1204 |
selected_dataset.change(
|
1205 |
+
fn=load_dataset,
|
1206 |
+
inputs=[selected_dataset],
|
1207 |
+
outputs=dataset_preview,
|
1208 |
+
)
|
1209 |
+
|
1210 |
+
selected_attributes.change(
|
1211 |
fn=generate_code_example,
|
1212 |
+
inputs=[selected_attributes],
|
1213 |
outputs=code_example,
|
1214 |
)
|
1215 |
|
1216 |
predict_button.click(
|
1217 |
+
fn=load_dataset_and_predict,
|
1218 |
+
inputs=[selected_dataset, selected_attributes, access_token],
|
1219 |
+
outputs=[dataset_preview, prediction_label, code_example],
|
|
|
|
|
|
|
|
|
|
|
1220 |
)
|
1221 |
|
1222 |
demo.load(
|
1223 |
fn=load_dataset_and_predict,
|
1224 |
+
inputs=[selected_dataset, selected_attributes, access_token],
|
1225 |
+
outputs=[dataset_preview, prediction_label, code_example],
|
1226 |
)
|
1227 |
|
1228 |
demo.launch()
|