Spaces:
Sleeping
Sleeping
Sync app files
Browse files- app/app.py +21 -17
app/app.py
CHANGED
|
@@ -10,7 +10,7 @@ METRICS_DIR = os.path.join(ROOT, "metrics")
|
|
| 10 |
MODEL_PATH = os.path.join(ROOT, "src", "model.pkl")
|
| 11 |
|
| 12 |
model = joblib.load(MODEL_PATH)
|
| 13 |
-
with open(os.path.join(METRICS_DIR,
|
| 14 |
metrics = json.load(f)
|
| 15 |
|
| 16 |
cat_options = {
|
|
@@ -18,7 +18,7 @@ cat_options = {
|
|
| 18 |
"device_type": ["Mobile", "Desktop", "Tablet"],
|
| 19 |
"ad_position": ["Top", "Side", "Bottom"],
|
| 20 |
"browsing_history": ["Sports", "News", "Shopping", "Other"],
|
| 21 |
-
"time_of_day": ["Morning", "Afternoon", "Evening", "Night"]
|
| 22 |
}
|
| 23 |
|
| 24 |
st.title("Ad Click Predictor")
|
|
@@ -29,20 +29,24 @@ st.markdown(
|
|
| 29 |
)
|
| 30 |
|
| 31 |
age = st.slider("Wiek użytkownika", 18, 64, 30)
|
| 32 |
-
gender = st.selectbox("Płeć", cat_options[
|
| 33 |
-
device_type = st.selectbox("Typ urządzenia", cat_options[
|
| 34 |
-
ad_position = st.selectbox("Pozycja reklamy", cat_options[
|
| 35 |
-
browsing_history = st.selectbox("Poprzednia aktywność", cat_options[
|
| 36 |
-
time_of_day = st.selectbox("Pora dnia", cat_options[
|
| 37 |
-
|
| 38 |
-
user_input = pd.DataFrame(
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
if st.button("Sprawdź czy użytkownik kliknie w reklamę"):
|
| 48 |
proba = model.predict_proba(user_input)[0][1]
|
|
@@ -59,4 +63,4 @@ st.write(f"- Accuracy: `{metrics['accuracy']:.2%}`")
|
|
| 59 |
st.write(f"- F1-score: `{metrics['f1_score']:.2%}`")
|
| 60 |
|
| 61 |
st.markdown("#### Macierz pomyłek (Confusion Matrix):")
|
| 62 |
-
st.image(os.path.join(METRICS_DIR,
|
|
|
|
| 10 |
MODEL_PATH = os.path.join(ROOT, "src", "model.pkl")
|
| 11 |
|
| 12 |
model = joblib.load(MODEL_PATH)
|
| 13 |
+
with open(os.path.join(METRICS_DIR, "metrics.json")) as f:
|
| 14 |
metrics = json.load(f)
|
| 15 |
|
| 16 |
cat_options = {
|
|
|
|
| 18 |
"device_type": ["Mobile", "Desktop", "Tablet"],
|
| 19 |
"ad_position": ["Top", "Side", "Bottom"],
|
| 20 |
"browsing_history": ["Sports", "News", "Shopping", "Other"],
|
| 21 |
+
"time_of_day": ["Morning", "Afternoon", "Evening", "Night"],
|
| 22 |
}
|
| 23 |
|
| 24 |
st.title("Ad Click Predictor")
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
age = st.slider("Wiek użytkownika", 18, 64, 30)
|
| 32 |
+
gender = st.selectbox("Płeć", cat_options["gender"])
|
| 33 |
+
device_type = st.selectbox("Typ urządzenia", cat_options["device_type"])
|
| 34 |
+
ad_position = st.selectbox("Pozycja reklamy", cat_options["ad_position"])
|
| 35 |
+
browsing_history = st.selectbox("Poprzednia aktywność", cat_options["browsing_history"])
|
| 36 |
+
time_of_day = st.selectbox("Pora dnia", cat_options["time_of_day"])
|
| 37 |
+
|
| 38 |
+
user_input = pd.DataFrame(
|
| 39 |
+
[
|
| 40 |
+
{
|
| 41 |
+
"age": age,
|
| 42 |
+
"gender": gender,
|
| 43 |
+
"device_type": device_type,
|
| 44 |
+
"ad_position": ad_position,
|
| 45 |
+
"browsing_history": browsing_history,
|
| 46 |
+
"time_of_day": time_of_day,
|
| 47 |
+
}
|
| 48 |
+
]
|
| 49 |
+
)
|
| 50 |
|
| 51 |
if st.button("Sprawdź czy użytkownik kliknie w reklamę"):
|
| 52 |
proba = model.predict_proba(user_input)[0][1]
|
|
|
|
| 63 |
st.write(f"- F1-score: `{metrics['f1_score']:.2%}`")
|
| 64 |
|
| 65 |
st.markdown("#### Macierz pomyłek (Confusion Matrix):")
|
| 66 |
+
st.image(os.path.join(METRICS_DIR, "confusion_matrix.png"))
|