Spaces:
Runtime error
Runtime error
Download src/prediction.py from fernandobriann/deployment: direct link, hf CLI and curl.
- Browser
- Download file 582 Bytes
-
https://huggingface.co/spaces/fernandobriann/deployment/resolve/main/src/prediction.py
- Command line
-
hf download hf://spaces/fernandobriann/deployment/src/prediction.py
-
curl -L -o prediction.py https://huggingface.co/spaces/fernandobriann/deployment/resolve/main/src/prediction.py
582 Bytes
| import pandas as pd | |
| def predict(data, model, prep): | |
| df = pd.DataFrame([data]) | |
| # Handle country | |
| top_country = ['PRT', 'GBR', 'FRA', 'ESP', 'DEU', 'ITA', 'IRL', 'BEL', 'BRA', 'NLD'] | |
| df['country'] = df['country'].apply(lambda x: x if x in top_country else 'Other') | |
| # Fix missing columns | |
| if 'agent' not in df.columns: | |
| df['agent'] = 0 | |
| if 'company' not in df.columns: | |
| df['company'] = 0 | |
| # Transform | |
| df_processed = prep.transform(df) | |
| # Predict | |
| result = model.predict(df_processed) | |
| return result[0] |