fbellomo commited on
Commit
e172540
·
verified ·
1 Parent(s): 0e63967

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -26,8 +26,38 @@ available_model_versions = ["Demographic Base"]
26
  default_model_version = "Demographic Base"
27
 
28
  def generate_code_example(dataset, attributes, model_version):
 
 
 
29
  code = f"""
30
  import fantix
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  """
32
  return code.strip()
33
 
@@ -112,7 +142,7 @@ with gr.Blocks(theme=interface_theme) as demo:
112
  dataset_preview = gr.Dataframe()
113
 
114
  with gr.Accordion("Code Example", open=False):
115
- code_example = gr.Code()
116
 
117
  predict_button = gr.Button("Predict Attributes")
118
 
 
26
  default_model_version = "Demographic Base"
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
35
+
36
+ client = fantix.Client(api_key="YOUR_API_KEY")
37
+
38
+ df = pd.DataFrame(
39
+ {
40
+ {
41
+ "Name": ["John", "Doe", "Jane", "Smith"],
42
+ "Age": [25, 30, 35, 40],
43
+ "Income": [50000, 60000, 70000, 80000],
44
+ "Marital Status": ["Single", "Married", "Single", "Married"],
45
+ "Education": ["High School", "Bachelor", "Master", "PhD"],
46
+ }
47
+ }
48
+ )
49
+
50
+ response = client.predict(
51
+ df=df,
52
+ attributes=[
53
+ fantix.type.INCOME,
54
+ fantix.type.AGE,
55
+ fantix.type.MARITAL_SATUS,
56
+ fantix.type.EDUCATION,
57
+ ],
58
+ prediction_columns=[{attributes_with_types}],
59
+ model_version='{model_version}'',
60
+ )
61
  """
62
  return code.strip()
63
 
 
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