Download app.py from Tirush12/test02: direct link, hf CLI and curl.
- Browser
- Download file 996 Bytes
-
https://huggingface.co/spaces/Tirush12/test02/resolve/main/app.py
- Command line
-
hf download hf://spaces/Tirush12/test02/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Tirush12/test02/resolve/main/app.py
996 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| import pandas as pd | |
| import joblib | |
| # Load the trained model | |
| model = joblib.load('personality_model.pkl') | |
| # Initialize the FastAPI app | |
| app = FastAPI(title="Personality Predictor API") | |
| # Define the expected input data format using Pydantic | |
| class UserData(BaseModel): | |
| Time_spent_Alone: float | |
| Stage_fear: str | |
| Social_event_attendance: float | |
| Going_outside: float | |
| Drained_after_socializing: str | |
| Friends_circle_size: float | |
| Post_frequency: float | |
| def home(): | |
| return {"message": "Personality Predictor API is running! Send a POST request to /predict."} | |
| def predict_personality(data: UserData): | |
| # Convert incoming JSON data into a pandas DataFrame (1 row) | |
| input_data = pd.DataFrame([data.dict()]) | |
| # Predict using the loaded model pipeline | |
| prediction = model.predict(input_data)[0] | |
| return {"Prediction": prediction} |