Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/dronabopche/100-ML-AI-Project/llms.txt

Use this file to discover all available pages before exploring further.

Each project that exposes a live prediction interface does so through a lightweight Flask REST API defined in src/app.py. The server accepts natural-language text describing the input, routes it through the Gemini API to extract structured feature values, runs those features through the preprocessing pipeline, and returns a JSON prediction. This design means callers do not need to know the model’s feature schema — they just describe the input in plain English.

Endpoints

GET /

Health check. Returns a confirmation message that the server is running. Useful for load balancer probes and smoke tests after deployment. Response
{
  "message": "House Price Prediction API is running"
}
curl example
curl http://localhost:5000/

POST /predict

Run model inference. Accepts a natural-language description of the input and returns the model’s prediction. Request body
prompt
string
required
A plain-English description of the property or entity to predict. The Gemini API parses this text and extracts the structured feature values the model needs.Example: "3-bedroom house built in 1990, lot area 8500 sq ft, RL zoning, inside lot configuration"
Response fields
predicted_sale_price
integer
The model’s predicted sale price in USD, computed as the average of Linear Regression, Ridge, and Lasso predictions.
error
string
Present only when the request fails. Describes the reason for the failure.
Success response
{
  "predicted_sale_price": 185000
}
Error responses
HTTP statusConditionBody
400prompt key missing from request body{"error": "Missing 'prompt' in request body"}
500GEMINI_API_KEY environment variable not set{"error": "GEMINI_API_KEY not set in environment"}
500Any unhandled exception during inference{"error": "<exception message>"}
curl example
curl -X POST http://localhost:5000/predict \
  -H "Content-Type: application/json" \
  -d '{"prompt": "3-bedroom house, built 1990, lot area 8500 sq ft, RL zoning, inside lot"}'

Gemini API integration

The Gemini API acts as a natural-language-to-structured-data converter. When a prediction request arrives, preprocess_prompt() sends the user’s free-text prompt to gemini-2.5-flash with a system prompt that instructs the model to return a JSON object containing specific house features.
system_prompt = f"""
You are an information extraction engine.

Extract these house features from the user prompt and return ONLY valid JSON.

Required keys:
{RAW_FEATURES}

Rules:
- Return JSON only, no explanation.
- If a value is missing, set it to null.
- Use correct datatypes:
  - MSSubClass: int
  - LotArea: int
  - OverallCond: int
  - YearBuilt: int
  - TotalBsmtSF: float or int
  - MSZoning, LotConfig, BldgType: string
"""

response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents=system_prompt + "\n\nUSER PROMPT:\n" + prompt,
)
The response is parsed as JSON. If Gemini returns a markdown code fence, the backticks are stripped before parsing. Any value that Gemini could not extract is set to null and replaced with a dataset-level default in the fill_missing() step.
def extract_features_from_prompt(prompt: str, gemini_api_key: str) -> dict:
    client = genai.Client(api_key=gemini_api_key)
    # ... (sends prompt to Gemini)
    text = (response.text or "").strip()
    if text.startswith("```"):
        text = text.replace("```json", "").replace("```", "").strip()
    try:
        return json.loads(text)
    except json.JSONDecodeError:
        return {key: None for key in RAW_FEATURES}  # safe fallback
You must set the GEMINI_API_KEY environment variable before starting the server. The API will return a 500 error on every /predict call if this variable is absent.
export GEMINI_API_KEY="your-api-key-here"
python src/app.py
Never hard-code your API key in source files or commit it to version control.

Complete app.py source

import os
from flask import Flask, request, jsonify
from flask_cors import CORS

from processing.preprocessing import preprocess_prompt
from output.predictor import predict_price

app = Flask(__name__)
CORS(app)

GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")


@app.route("/", methods=["GET"])
def home():
    return jsonify({"message": "House Price Prediction API is running"})


@app.route("/predict", methods=["POST"])
def predict():
    try:
        body = request.get_json()

        if not body or "prompt" not in body:
            return jsonify({"error": "Missing 'prompt' in request body"}), 400

        prompt = body["prompt"]

        if not GEMINI_API_KEY:
            return jsonify({"error": "GEMINI_API_KEY not set in environment"}), 500

        features_np = preprocess_prompt(prompt, GEMINI_API_KEY)
        predicted_price = int(predict_price(features_np))

        return jsonify({
            "predicted_sale_price": predicted_price
        })

    except Exception as e:
        return jsonify({"error": str(e)}), 500


if __name__ == "__main__":
    app.run(debug=True)

Build docs developers (and LLMs) love