MarjG commited on
Commit
446a0a3
·
1 Parent(s): 3a272d0

modif app.py

Browse files
Files changed (2) hide show
  1. app.py +3 -2
  2. test.py +10 -10
app.py CHANGED
@@ -108,7 +108,7 @@ async def unique_values(column: str):
108
  """
109
  df = pd.read_csv("https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_pricing_project.csv", index_col=0)
110
  unique_vals = df[column].dropna().unique().tolist()
111
-
112
  return unique_vals
113
 
114
 
@@ -150,7 +150,8 @@ async def group_by(groupBy: GroupBy):
150
  if method == "count":
151
  df = df.groupby(groupBy.column)[numeric_cols].count()
152
 
153
- return df.to_json()
 
154
 
155
 
156
  @app.get("/filter-by", tags=["Categorical"])
 
108
  """
109
  df = pd.read_csv("https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_pricing_project.csv", index_col=0)
110
  unique_vals = df[column].dropna().unique().tolist()
111
+
112
  return unique_vals
113
 
114
 
 
150
  if method == "count":
151
  df = df.groupby(groupBy.column)[numeric_cols].count()
152
 
153
+ df = df.reset_index()
154
+ return df.to_json(orient="records")
155
 
156
 
157
  @app.get("/filter-by", tags=["Categorical"])
test.py CHANGED
@@ -12,7 +12,7 @@ def test_preview():
12
  response = r.json()
13
  print(pd.DataFrame(json.loads(response)))
14
 
15
- #test_preview()
16
 
17
 
18
  ### Test uniquevalues endpoint
@@ -20,10 +20,10 @@ def test_uniquevalues():
20
  print("###test_uniquevalues###")
21
 
22
  payload = {"column": "model_key"}
23
- r = requests.get("https://marjg-getaround-api.hf.space/unique-values", data=json.dumps(payload))
24
 
25
  response = r.json()
26
- print(json.dumps(response, indent=2))
27
 
28
  test_uniquevalues()
29
 
@@ -33,12 +33,12 @@ def test_groupby():
33
  print("###test_groupby###")
34
 
35
  payload = {"column": "model_key", "by_method": "mean"}
36
- r = requests.get("https://marjg-getaround-api.hf.space/groupby", data=json.dumps(payload))
37
 
38
  response = r.json()
39
- print(response)
40
 
41
- #test_groupby()
42
 
43
 
44
  ### Test filter-by endpoint
@@ -50,12 +50,12 @@ def test_filterBy():
50
  "by_category": ["black", "grey"],
51
  }
52
 
53
- r = requests.get("https://marjg-getaround-api.hf.space/filter-by", data=json.dumps(payload))
54
 
55
  response = r.json()
56
  print(pd.read_json(response))
57
 
58
- #test_filterBy()
59
 
60
 
61
  #### Test ML Model
@@ -83,7 +83,7 @@ def test_prediction():
83
  response = r.json()
84
  print(round(response["prediction"], 2))
85
 
86
- #test_prediction()
87
 
88
 
89
  #### Test batch pred
@@ -99,4 +99,4 @@ def test_batch():
99
  response = r.json()
100
  print(pd.DataFrame(response))
101
 
102
- #test_batch()
 
12
  response = r.json()
13
  print(pd.DataFrame(json.loads(response)))
14
 
15
+ test_preview()
16
 
17
 
18
  ### Test uniquevalues endpoint
 
20
  print("###test_uniquevalues###")
21
 
22
  payload = {"column": "model_key"}
23
+ r = requests.get("https://marjg-getaround-api.hf.space/unique-values", params=payload)
24
 
25
  response = r.json()
26
+ print(response)
27
 
28
  test_uniquevalues()
29
 
 
33
  print("###test_groupby###")
34
 
35
  payload = {"column": "model_key", "by_method": "mean"}
36
+ r = requests.get("https://marjg-getaround-api.hf.space/groupby", params=payload)
37
 
38
  response = r.json()
39
+ print(pd.DataFrame(response))
40
 
41
+ test_groupby()
42
 
43
 
44
  ### Test filter-by endpoint
 
50
  "by_category": ["black", "grey"],
51
  }
52
 
53
+ r = requests.get("https://marjg-getaround-api.hf.space/filter-by", params=payload)
54
 
55
  response = r.json()
56
  print(pd.read_json(response))
57
 
58
+ test_filterBy()
59
 
60
 
61
  #### Test ML Model
 
83
  response = r.json()
84
  print(round(response["prediction"], 2))
85
 
86
+ test_prediction()
87
 
88
 
89
  #### Test batch pred
 
99
  response = r.json()
100
  print(pd.DataFrame(response))
101
 
102
+ test_batch()