|
import gradio as gr |
|
import numpy as np |
|
import os |
|
from huggingface_hub import hf_hub_download |
|
import joblib |
|
import pandas as pd |
|
|
|
|
|
hf_token = os.getenv("HF_TOKEN") |
|
model_path = hf_hub_download(repo_id="wvsu-dti-aidev-team/advertising_knn_regressor_model", filename="decision_tree_regressor.pkl", use_auth_token=hf_token) |
|
model = joblib.load(model_path) |
|
|
|
def predict_sales(tv, radio, newspaper): |
|
|
|
input_data = pd.DataFrame([[tv, radio, newspaper]], columns=['TV', 'Radio', 'Newspaper']) |
|
|
|
|
|
predicted_sales = model.predict(input_data) |
|
|
|
|
|
discussion = f"Based on the advertising spending, the projected sales are approximately {predicted_sales[0] * 10000:.2f} Pesos. " \ |
|
f"Investing more in TV advertising tends to have a significant impact on sales, followed by Radio and Newspaper. " \ |
|
f"Optimizing the budget allocation across these channels can help maximize sales." |
|
|
|
return predicted_sales[0], discussion |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_sales, |
|
inputs=[ |
|
gr.Number(label="TV Advertising Spend (x 10,000 Pesos)"), |
|
gr.Number(label="Radio Advertising Spend (x 10,000 Pesos)"), |
|
gr.Number(label="Newspaper Advertising Spend (x 10,000 Pesos)") |
|
], |
|
outputs=[ |
|
gr.Textbox(label="Predicted Sales"), |
|
gr.Textbox(label="Discussion") |
|
], |
|
title="Advertising Spend to Sales Prediction", |
|
description="Enter the advertising spending on TV, Radio, and Newspaper to predict the sales." |
|
) |
|
|
|
|
|
iface.launch() |