|
|
|
|
|
import panda as pd |
|
|
import gradio |
|
|
import numpy as np |
|
|
import pickle |
|
|
|
|
|
|
|
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
|
|
|
HF_TOKEN = os.environ.get("HF_TOKEN") |
|
|
|
|
|
HF_MODEL_ID = os.environ.get("HF_MODEL_ID", "SpringyBon/entrepreneur-readiness-regressor") |
|
|
|
|
|
def _download(fname: str) -> str: |
|
|
return hf_hub_download( |
|
|
repo_id=HF_MODEL_ID, |
|
|
filename=fname, |
|
|
token=HF_TOKEN, |
|
|
repo_type="model" |
|
|
) |
|
|
|
|
|
model_path = _download("model.pkl") |
|
|
feat_path = _download("feature_names.json") |
|
|
|
|
|
reg = pickle.load(model_path) |
|
|
with open(feat_path, "r") as f: |
|
|
FEATURES = json.load(f) |
|
|
|
|
|
def predict( |
|
|
savings_amount, monthly_income, monthly_expenses, monthly_entertainment, |
|
|
sales_skills_1to10, age, dependents, assets_count, risk_tolerance_1to10, |
|
|
confidence_1to10, business_idea_difficulty_1to10, disposable_income, |
|
|
runway_months, income_stability_1to10, prior_experience_years, credit_score |
|
|
): |
|
|
sample = { |
|
|
"savings_amount": savings_amount, |
|
|
"monthly_income": monthly_income, |
|
|
"monthly_expenses": monthly_expenses, |
|
|
"monthly_entertainment": monthly_entertainment, |
|
|
"sales_skills_1to10": sales_skills_1to10, |
|
|
"age": age, |
|
|
"dependents": dependents, |
|
|
"assets_count": assets_count, |
|
|
"risk_tolerance_1to10": risk_tolerance_1to10, |
|
|
"confidence_1to10": confidence_1to10, |
|
|
"business_idea_difficulty_1to10": business_idea_difficulty_1to10, |
|
|
"disposable_income": disposable_income, |
|
|
"runway_months": runway_months, |
|
|
"income_stability_1to10": income_stability_1to10, |
|
|
"prior_experience_years": prior_experience_years, |
|
|
"credit_score": credit_score, |
|
|
} |
|
|
try: |
|
|
x = [sample[f] for f in FEATURES] |
|
|
except KeyError as e: |
|
|
return f"Missing feature: {e}" |
|
|
pred = float(reg.predict(np.array(x, dtype=float).reshape(1, -1))[0]) |
|
|
return round(pred, 2) |
|
|
|
|
|
with gr.Blocks(title="Entrepreneur Readiness Regressor") as demo: |
|
|
gr.Markdown("## Entrepreneur Readiness β Prediction Demo") |
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
savings_amount = gr.Number(label="Savings Amount", value=25000) |
|
|
monthly_income = gr.Number(label="Monthly Income", value=5000) |
|
|
monthly_expenses = gr.Number(label="Monthly Expenses", value=3000) |
|
|
monthly_entertainment = gr.Number(label="Monthly Entertainment", value=200) |
|
|
sales_skills_1to10 = gr.Slider(1, 10, value=7, step=1, label="Sales Skills (1-10)") |
|
|
age = gr.Number(label="Age", value=32) |
|
|
dependents = gr.Number(label="Dependents", value=1, precision=0) |
|
|
with gr.Column(): |
|
|
assets_count = gr.Number(label="Assets Count", value=2, precision=0) |
|
|
risk_tolerance_1to10 = gr.Slider(1, 10, value=6, step=1, label="Risk Tolerance (1-10)") |
|
|
confidence_1to10 = gr.Slider(1, 10, value=8, step=1, label="Confidence (1-10)") |
|
|
business_idea_difficulty_1to10 = gr.Slider(1, 10, value=5, step=1, label="Idea Difficulty (1-10)") |
|
|
disposable_income = gr.Number(label="Disposable Income", value=2000) |
|
|
runway_months = gr.Number(label="Runway (months)", value=12, precision=0) |
|
|
income_stability_1to10 = gr.Slider(1, 10, value=7, step=1, label="Income Stability (1-10)") |
|
|
prior_experience_years = gr.Number(label="Prior Experience (years)", value=4) |
|
|
credit_score = gr.Number(label="Credit Score", value=710, precision=0) |
|
|
output = gr.Number(label="Predicted Readiness Score", precision=2) |
|
|
gr.Button("Predict Readiness").click( |
|
|
predict, |
|
|
inputs=[savings_amount, monthly_income, monthly_expenses, monthly_entertainment, |
|
|
sales_skills_1to10, age, dependents, assets_count, risk_tolerance_1to10, |
|
|
confidence_1to10, business_idea_difficulty_1to10, disposable_income, |
|
|
runway_months, income_stability_1to10, prior_experience_years, credit_score], |
|
|
outputs=output |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|
|
|
|