Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
|
@@ -73,40 +73,19 @@ class FilterBy(BaseModel):
|
|
| 73 |
|
| 74 |
|
| 75 |
class PredictionFeatures(BaseModel):
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
JobLevel: Union[int, float]
|
| 90 |
-
JobRole: str
|
| 91 |
-
JobSatisfaction: Union[int, float]
|
| 92 |
-
MaritalStatus: str
|
| 93 |
-
MonthlyIncome: Union[int, float]
|
| 94 |
-
MonthlyRate: Union[int, float]
|
| 95 |
-
NumCompaniesWorked: Union[int, float]
|
| 96 |
-
Over18: str
|
| 97 |
-
OverTime: str
|
| 98 |
-
PercentSalaryHike: Union[int, float]
|
| 99 |
-
PerformanceRating: Union[int, float]
|
| 100 |
-
RelationshipSatisfaction: Union[int, float]
|
| 101 |
-
StandardHours: Union[int, float]
|
| 102 |
-
StockOptionLevel: Union[int, float]
|
| 103 |
-
TotalWorkingYears: Union[int, float]
|
| 104 |
-
TrainingTimesLastYear: Union[int, float]
|
| 105 |
-
WorkLifeBalance: Union[int, float]
|
| 106 |
-
YearsAtCompany: Union[int, float]
|
| 107 |
-
YearsInCurrentRole: Union[int, float]
|
| 108 |
-
YearsSinceLastPromotion: Union[int, float]
|
| 109 |
-
YearsWithCurrManager: Union[int, float]
|
| 110 |
|
| 111 |
|
| 112 |
@app.get("/", tags=["Introduction Endpoints"])
|
|
@@ -119,12 +98,12 @@ async def index():
|
|
| 119 |
|
| 120 |
|
| 121 |
@app.get("/preview", tags=["Preview"])
|
| 122 |
-
async def
|
| 123 |
"""
|
| 124 |
Get a sample of your whole dataset.
|
| 125 |
You can specify how many rows you want by specifying a value for `rows`, default is `10`
|
| 126 |
"""
|
| 127 |
-
df = pd.
|
| 128 |
sample = df.sample(rows)
|
| 129 |
return sample.to_json()
|
| 130 |
|
|
@@ -134,42 +113,18 @@ async def unique_values(column: str):
|
|
| 134 |
"""
|
| 135 |
Get unique values from a given column
|
| 136 |
"""
|
| 137 |
-
df = pd.
|
| 138 |
df = pd.Series(df[column].unique())
|
| 139 |
|
| 140 |
return df.to_json()
|
| 141 |
|
| 142 |
|
| 143 |
-
@app.get("/quantile", tags=["Numerical"])
|
| 144 |
-
async def quantile(column: str, percent: float = 0.1, top: bool = True):
|
| 145 |
-
"""
|
| 146 |
-
Get a values of HR dataset according above or below a given quantile.
|
| 147 |
-
*i.e* with this dataset, you can have the top 10% values of the dataset given a certain column
|
| 148 |
-
|
| 149 |
-
You can choose whether you want the top quantile or the bottom quantile by specify `top=True` or `top=False`. Default value is `top=True`
|
| 150 |
-
Accepted values for percentage is a float between `0.01` and `0.99`, default is `0.1`
|
| 151 |
-
"""
|
| 152 |
-
|
| 153 |
-
df = pd.read_excel("data/ibm_hr_attrition.xlsx")
|
| 154 |
-
|
| 155 |
-
if percent > 0.99 or percent < 0.01:
|
| 156 |
-
msg = "percentage value is not accepted"
|
| 157 |
-
return msg
|
| 158 |
-
else:
|
| 159 |
-
if top:
|
| 160 |
-
df = df[df[column] > df[column].quantile(1 - percent)]
|
| 161 |
-
else:
|
| 162 |
-
df = df[df[column] < df[column].quantile(percent)]
|
| 163 |
-
|
| 164 |
-
return df.to_json()
|
| 165 |
-
|
| 166 |
-
|
| 167 |
@app.post("/groupby", tags=["Categorical"])
|
| 168 |
async def group_by(groupBy: GroupBy):
|
| 169 |
"""
|
| 170 |
Get data grouped by a given column. Accepted columns are:
|
| 171 |
|
| 172 |
-
* `["
|
| 173 |
|
| 174 |
You can use different method to group by category which are:
|
| 175 |
|
|
@@ -181,7 +136,7 @@ async def group_by(groupBy: GroupBy):
|
|
| 181 |
* `count`
|
| 182 |
"""
|
| 183 |
|
| 184 |
-
df = pd.
|
| 185 |
|
| 186 |
method = groupBy.by_method
|
| 187 |
|
|
@@ -206,13 +161,13 @@ async def filter_by(filterBy: FilterBy):
|
|
| 206 |
"""
|
| 207 |
Filter by one or more categories in a given column. Columns possible values are:
|
| 208 |
|
| 209 |
-
* `["
|
| 210 |
|
| 211 |
Check values within dataset to know what kind of `categories` you can filter by. You can use `/unique-values` path to check them out.
|
| 212 |
`categories` must be `list` format.
|
| 213 |
"""
|
| 214 |
|
| 215 |
-
df = pd.
|
| 216 |
|
| 217 |
if filterBy.by_category != None:
|
| 218 |
df = df[df[filterBy.column].isin(filterBy.by_category)]
|
|
@@ -228,13 +183,12 @@ async def predict(predictionFeatures: PredictionFeatures):
|
|
| 228 |
Prediction for one observation. Endpoint will return a dictionnary like this:
|
| 229 |
|
| 230 |
```
|
| 231 |
-
{'prediction': PREDICTION_VALUE
|
| 232 |
```
|
| 233 |
|
| 234 |
You need to give this endpoint all columns values as dictionnary, or form data.
|
| 235 |
"""
|
| 236 |
# Read data
|
| 237 |
-
# df = pd.DataFrame(dict(predictionFeatures), index=[0])
|
| 238 |
df = pd.DataFrame([predictionFeatures.dict()])
|
| 239 |
# Log model from mlflow
|
| 240 |
logged_model = "runs:/21ce144d259c49a6a7a7e28be3fccecb/getaround_pricing_optimization"
|
|
|
|
| 73 |
|
| 74 |
|
| 75 |
class PredictionFeatures(BaseModel):
|
| 76 |
+
Model: str
|
| 77 |
+
Mileage: Union[int, float]
|
| 78 |
+
EnginePower: Union[int, float]
|
| 79 |
+
Fuel: str
|
| 80 |
+
PaintColor: str
|
| 81 |
+
CarType: str
|
| 82 |
+
PrivateParkingAvailable: Literal["True", "False"]
|
| 83 |
+
HasGPS: Literal["True", "False"]
|
| 84 |
+
HasAirConditioning: Literal["True", "False"]
|
| 85 |
+
Automatic : Literal["True", "False"]
|
| 86 |
+
HasGetAroundConnect: Literal["True", "False"]
|
| 87 |
+
HasSpeedRegulator: Literal["True", "False"]
|
| 88 |
+
WinterTires: Literal["True", "False"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
@app.get("/", tags=["Introduction Endpoints"])
|
|
|
|
| 98 |
|
| 99 |
|
| 100 |
@app.get("/preview", tags=["Preview"])
|
| 101 |
+
async def random_cars(rows: int = 10):
|
| 102 |
"""
|
| 103 |
Get a sample of your whole dataset.
|
| 104 |
You can specify how many rows you want by specifying a value for `rows`, default is `10`
|
| 105 |
"""
|
| 106 |
+
df = pd.read_csv("https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_pricing_project.csv", index_col=0)
|
| 107 |
sample = df.sample(rows)
|
| 108 |
return sample.to_json()
|
| 109 |
|
|
|
|
| 113 |
"""
|
| 114 |
Get unique values from a given column
|
| 115 |
"""
|
| 116 |
+
df = pd.read_csv("https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_pricing_project.csv", index_col=0)
|
| 117 |
df = pd.Series(df[column].unique())
|
| 118 |
|
| 119 |
return df.to_json()
|
| 120 |
|
| 121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
@app.post("/groupby", tags=["Categorical"])
|
| 123 |
async def group_by(groupBy: GroupBy):
|
| 124 |
"""
|
| 125 |
Get data grouped by a given column. Accepted columns are:
|
| 126 |
|
| 127 |
+
* `["Model","Fuel", "PaintColor", "CarType"]`
|
| 128 |
|
| 129 |
You can use different method to group by category which are:
|
| 130 |
|
|
|
|
| 136 |
* `count`
|
| 137 |
"""
|
| 138 |
|
| 139 |
+
df = pd.read_csv("https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_pricing_project.csv", index_col=0)
|
| 140 |
|
| 141 |
method = groupBy.by_method
|
| 142 |
|
|
|
|
| 161 |
"""
|
| 162 |
Filter by one or more categories in a given column. Columns possible values are:
|
| 163 |
|
| 164 |
+
* `["Model","Fuel", "PaintColor", "CarType"]`
|
| 165 |
|
| 166 |
Check values within dataset to know what kind of `categories` you can filter by. You can use `/unique-values` path to check them out.
|
| 167 |
`categories` must be `list` format.
|
| 168 |
"""
|
| 169 |
|
| 170 |
+
df = pd.read_csv("https://full-stack-assets.s3.eu-west-3.amazonaws.com/Deployment/get_around_pricing_project.csv", index_col=0)
|
| 171 |
|
| 172 |
if filterBy.by_category != None:
|
| 173 |
df = df[df[filterBy.column].isin(filterBy.by_category)]
|
|
|
|
| 183 |
Prediction for one observation. Endpoint will return a dictionnary like this:
|
| 184 |
|
| 185 |
```
|
| 186 |
+
{'prediction': PREDICTION_VALUE}
|
| 187 |
```
|
| 188 |
|
| 189 |
You need to give this endpoint all columns values as dictionnary, or form data.
|
| 190 |
"""
|
| 191 |
# Read data
|
|
|
|
| 192 |
df = pd.DataFrame([predictionFeatures.dict()])
|
| 193 |
# Log model from mlflow
|
| 194 |
logged_model = "runs:/21ce144d259c49a6a7a7e28be3fccecb/getaround_pricing_optimization"
|