harbor run -t openthoughts/tasktrove-exp-rpt-scaffold-v2-scaffold-1458harbor download openthoughts/tasktrove-exp-rpt-scaffold-v2-scaffold-1458Task: Implement the missing pieces to provide a simple Flask prediction API and a small pickle-based dummy model workflow.
What needs to be implemented
- In app.py:
- Replace the placeholder NotImplementedError stubs with functional code.
- Implement a lightweight DummyModel that can be instantiated and has a predict method compatible with a pandas DataFrame input.
- Implement create_app so that:
- It loads a model instance from the pickle file named xgb_reg_fourteen_features1.pickle (path defined by PICKLE_FILENAME).
- It exposes a Flask route at ENDPOINT ("/predict") that accepts query parameters corresponding to the features defined in FeatureDict.
- It builds a pandas DataFrame representing a single example from the provided query parameters (use sensible defaults, e.g., 0, for any missing features).
- It calls model.predict on that DataFrame and returns a plain text response containing the predicted value (the first element of the list returned by predict).
- It handles errors gracefully (e.g., missing/invalid inputs) and returns an appropriate HTTP error if needed.
- Ensure create_app returns a Flask app instance ready to run.
- In create_pickle.py:
- Implement DummyModelForPickle so that it can be pickled and its predict method returns a deterministic, single numeric value for a given DataFrame.
- Implement create_pickle to instantiate DummyModelForPickle and pickle it to the file named xgb_reg_fourteen_features1.pickle.
- Ensure the __main__ block executes a pickle creation flow (i.e., running the script directly should generate the pickle file).
What each class/function is for and how it should behave
- FeatureDict (TypedDict, total=False)
- Documents the feature keys accepted by the API (all optional). Keys include: bedrooms, bathrooms, accommodates, instant_bookable, minimum_nights, maximum_nights, wifi, kitchen, heating, air_conditioning, tv.
- Used to guide input parsing and DataFrame construction.
- DummyModel
- A simple model placeholder used for typing and potential future testing.
- Should provide a predictable interface: __init__ initializes internal state; predict(X: pd.DataFrame) -> List[float] returns a list with one numeric value when given a single-row DataFrame.
- The implementation should be lightweight and deterministic.
- create_app() -> "Flask"
- Creates and configures the Flask application.
- Loads the model from the pickle file (PICKLE_FILENAME).
- Sets up the /predict endpoint to:
- Read query parameters for the supported features.
- Build a one-row pandas DataFrame from those parameters (default missing values to reasonable defaults, e.g., 0).
- Call model.predict and return the first (and only) value as a string response.
- Provide minimal error handling and clear responses for invalid inputs.
- DummyModelForPickle (in create_pickle.py)
- A simple, deterministic model intended solely for pickle creation.
- __init__ should initialize any needed state (no NotImplementedError).
- predict(X: pd.DataFrame) -> List[float] returns a deterministic numeric value based on the input DataFrame (e.g., a consistent function of the input row).
- create_pickle() (in create_pickle.py)
- Creates an instance of DummyModelForPickle and pickles it to the file specified by PICKLE_FILENAME.
- The function should be safe to call multiple times; if the file exists, it may overwrite it or replace it as appropriate.
- __main__ entrypoint (in create_pickle.py)
- When the module is run as a script, execute the pickle creation flow (i.e., call create_pickle()).
Files to modify (in /app/)
- app.py
- create_pickle.py
Tests and execution
- The project will be tested with pytest.
- Tests will likely verify:
- The presence and shape of the /predict endpoint and its basic behavior (accepts inputs, returns a numeric string).
- The ability to load the model from the pickle file and invoke predict with a valid DataFrame.
- The pickle creation flow produces a file named xgb_reg_fourteen_features1.pickle containing a pickleable model with a deterministic predict method.
- Do not reveal or rely on any specific numerical values in the implementation; ensure the behavior is correct and deterministic, suitable for tests to assert on basic contract (interface and response type).
Notes
- The exact implementation details (e.g., how the numeric prediction is computed) should be defined in terms of behavior, not copied code. The tests will check for the correct interfaces, loading behavior, input handling, and response format.
- If a parameter is provided in the query string, it should be treated as an integer (where appropriate) and included in the DataFrame; if it cannot be parsed, respond with an informative error.
- The endpoint should return a plain text representation of the predicted value (not JSON) unless the tests specify otherwise.
Remember: Implement behavior to satisfy tests, but do not disclose concrete implementations beyond what is described here.
Important: place your implementation at /app/app.py so the tests can import app.