sync to remote
Browse files- app.py +44 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import os
|
4 |
+
from huggingface_hub import hf_hub_download
|
5 |
+
import joblib # Import joblib directly
|
6 |
+
import pandas as pd
|
7 |
+
|
8 |
+
# Load the pre-trained model from Hugging Face
|
9 |
+
hf_token = os.getenv("HF_TOKEN")
|
10 |
+
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)
|
11 |
+
model = joblib.load(model_path)
|
12 |
+
|
13 |
+
def predict_sales(tv, radio, newspaper):
|
14 |
+
# Create a DataFrame with the same feature names as the training data
|
15 |
+
input_data = pd.DataFrame([[tv, radio, newspaper]], columns=['TV', 'Radio', 'Newspaper'])
|
16 |
+
|
17 |
+
# Get the predicted sales
|
18 |
+
predicted_sales = model.predict(input_data)
|
19 |
+
|
20 |
+
# Discussion on the projected sales result
|
21 |
+
discussion = f"Based on the advertising spending, the projected sales are approximately {predicted_sales[0] * 10000:.2f} Pesos. " \
|
22 |
+
f"Investing more in TV advertising tends to have a significant impact on sales, followed by Radio and Newspaper. " \
|
23 |
+
f"Optimizing the budget allocation across these channels can help maximize sales."
|
24 |
+
|
25 |
+
return predicted_sales[0], discussion
|
26 |
+
|
27 |
+
# Create the Gradio interface
|
28 |
+
iface = gr.Interface(
|
29 |
+
fn=predict_sales,
|
30 |
+
inputs=[
|
31 |
+
gr.Number(label="TV Advertising Spend (x 10,000 Pesos)"),
|
32 |
+
gr.Number(label="Radio Advertising Spend (x 10,000 Pesos)"),
|
33 |
+
gr.Number(label="Newspaper Advertising Spend (x 10,000 Pesos)")
|
34 |
+
],
|
35 |
+
outputs=[
|
36 |
+
gr.Textbox(label="Predicted Sales"),
|
37 |
+
gr.Textbox(label="Discussion")
|
38 |
+
],
|
39 |
+
title="Advertising Spend to Sales Prediction",
|
40 |
+
description="Enter the advertising spending on TV, Radio, and Newspaper to predict the sales."
|
41 |
+
)
|
42 |
+
|
43 |
+
# Launch the app
|
44 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
scikit-learn
|
4 |
+
huggingface_hub
|
5 |
+
joblib
|
6 |
+
pandas
|