fbellomo commited on
Commit
7b87645
·
verified ·
1 Parent(s): ec0d106

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -425,10 +425,15 @@ default_attributes = [
425
  def dataframe_to_code(df):
426
  df = df.head(4)
427
  columns = df.columns.tolist()
428
- dict_string = ", ".join([f"'{col}': {df[col].tolist()}" for col in columns])
429
- code_string = f"df = pd.DataFrame(\n {{{dict_string}}}\n)"
 
 
 
 
430
  return code_string
431
 
 
432
  def generate_code_example(dataset, attributes):
433
  attributes_with_types = ", \n".join(
434
  [f"\t\tfantix.type.{attr.upper().replace(' ', '_')}" for attr in attributes]
@@ -439,6 +444,7 @@ def generate_code_example(dataset, attributes):
439
  code = f"""
440
  import fantix
441
  import pandas as pd
 
442
  client = fantix.Client(api_key="YOUR_API_KEY")
443
 
444
  {dataframe_code}
@@ -1106,27 +1112,27 @@ def predict(dataset, attributes, access_token):
1106
  - attributes (list): The attributes to predict.
1107
  - access_token (str): The access token for API authentication.
1108
  Returns:
1109
- - tuple: A message about the prediction, prediction results as a DataFrame,
1110
  and the number of predictions made in the given time frame.
1111
  """
1112
  api_url = "https://rb3mw988lz88cvpz.us-east-1.aws.endpoints.huggingface.cloud"
1113
  headers = {
1114
  "Accept": "application/json",
1115
  "Authorization": f"Bearer {access_token}",
1116
- "Content-Type": "application/json"
1117
  }
1118
-
1119
  payload = {
1120
  "inputs": [
1121
  {
1122
  "input_data": dataset.to_dict(orient="records"),
1123
  "attributes_to_predict": [
1124
- attribute.lower().replace(" ", "_") for attribute in attributes
1125
  ],
1126
  }
1127
  ],
1128
  }
1129
-
1130
  start_time = time.time()
1131
  response = requests.post(api_url, headers=headers, json=payload)
1132
  end_time = time.time()
@@ -1144,9 +1150,10 @@ def predict(dataset, attributes, access_token):
1144
 
1145
  return prediction_message, prediction_results
1146
 
 
1147
  def load_dataset_and_predict(dataset, attributes, access_token):
1148
  loaded_data = load_dataset(dataset)
1149
-
1150
  code_example = generate_code_example(dataset, attributes)
1151
 
1152
  if access_token:
 
425
  def dataframe_to_code(df):
426
  df = df.head(4)
427
  columns = df.columns.tolist()
428
+ dict_entries = []
429
+ for col in columns:
430
+ values_list = repr(df[col].tolist())
431
+ dict_entries.append(f" '{col}': {values_list}")
432
+ dict_string = ",\n".join(dict_entries)
433
+ code_string = f"df = pd.DataFrame(\n {{\n{dict_string}\n }}\n)"
434
  return code_string
435
 
436
+
437
  def generate_code_example(dataset, attributes):
438
  attributes_with_types = ", \n".join(
439
  [f"\t\tfantix.type.{attr.upper().replace(' ', '_')}" for attr in attributes]
 
444
  code = f"""
445
  import fantix
446
  import pandas as pd
447
+
448
  client = fantix.Client(api_key="YOUR_API_KEY")
449
 
450
  {dataframe_code}
 
1112
  - attributes (list): The attributes to predict.
1113
  - access_token (str): The access token for API authentication.
1114
  Returns:
1115
+ - tuple: A message about the prediction, prediction results as a DataFrame,
1116
  and the number of predictions made in the given time frame.
1117
  """
1118
  api_url = "https://rb3mw988lz88cvpz.us-east-1.aws.endpoints.huggingface.cloud"
1119
  headers = {
1120
  "Accept": "application/json",
1121
  "Authorization": f"Bearer {access_token}",
1122
+ "Content-Type": "application/json",
1123
  }
1124
+
1125
  payload = {
1126
  "inputs": [
1127
  {
1128
  "input_data": dataset.to_dict(orient="records"),
1129
  "attributes_to_predict": [
1130
+ attribute.lower().replace(" ", "_") for attribute in attributes
1131
  ],
1132
  }
1133
  ],
1134
  }
1135
+
1136
  start_time = time.time()
1137
  response = requests.post(api_url, headers=headers, json=payload)
1138
  end_time = time.time()
 
1150
 
1151
  return prediction_message, prediction_results
1152
 
1153
+
1154
  def load_dataset_and_predict(dataset, attributes, access_token):
1155
  loaded_data = load_dataset(dataset)
1156
+
1157
  code_example = generate_code_example(dataset, attributes)
1158
 
1159
  if access_token: