Spaces:
Sleeping
Sleeping
Update app.py from Colab
Browse files
app.py
CHANGED
|
@@ -6,8 +6,10 @@ import pandas # For tabular data handling
|
|
| 6 |
import gradio # For interactive UI
|
| 7 |
import huggingface_hub # For downloading model assets
|
| 8 |
import autogluon.tabular # For loading and running AutoGluon predictors
|
| 9 |
-
|
| 10 |
# Settings
|
|
|
|
|
|
|
| 11 |
MODEL_REPO_ID = "jennifee/classical_automl_model"
|
| 12 |
ZIP_FILENAME = "autogluon_predictor_dir.zip"
|
| 13 |
CACHE_DIR = pathlib.Path("hf_assets")
|
|
@@ -22,6 +24,7 @@ FEATURE_COLS = ['phone_hours',
|
|
| 22 |
]
|
| 23 |
TARGET_COL = "sleep_quality"
|
| 24 |
# Encoding for likert questions
|
|
|
|
| 25 |
LIKERT5_LABELS = ["Never", "Rarely", "Sometimes", "Often", "Very Often"]
|
| 26 |
LIKERT5_MAP = {label: idx for idx, label in enumerate(LIKERT5_LABELS)}
|
| 27 |
|
|
@@ -77,9 +80,9 @@ def do_predict(phone_hours, computer_hours, device_count, use_before_bed_label,
|
|
| 77 |
FEATURE_COLS[0]: float(phone_hours),
|
| 78 |
FEATURE_COLS[1]: float(computer_hours),
|
| 79 |
FEATURE_COLS[2]: int(device_count),
|
| 80 |
-
FEATURE_COLS[
|
| 81 |
-
FEATURE_COLS[
|
| 82 |
-
FEATURE_COLS[
|
| 83 |
}
|
| 84 |
X = pandas.DataFrame([row], columns=[col for col in FEATURE_COLS if col != TARGET_COL]) # Exclude target column from input
|
| 85 |
|
|
@@ -147,11 +150,11 @@ with gradio.Blocks() as demo:
|
|
| 147 |
device_count = gradio.Number(value=3, precision=0, label=FEATURE_COLS[2])
|
| 148 |
|
| 149 |
with gradio.Row():
|
| 150 |
-
use_before_bed_label = gradio.Radio(choices=LIKERT5_LABELS, value="Sometimes", label=FEATURE_COLS[
|
| 151 |
|
| 152 |
with gradio.Row():
|
| 153 |
-
sleep_time = gradio.Slider(0, 24, step=0.1, value=23.0, label=FEATURE_COLS[
|
| 154 |
-
sleep_hours = gradio.Slider(0, 12, step=0.1, value=7.0, label=FEATURE_COLS[
|
| 155 |
|
| 156 |
|
| 157 |
proba_pretty = gradio.Label(num_top_classes=2, label="Class probabilities") # Changed to 2 classes
|
|
|
|
| 6 |
import gradio # For interactive UI
|
| 7 |
import huggingface_hub # For downloading model assets
|
| 8 |
import autogluon.tabular # For loading and running AutoGluon predictors
|
| 9 |
+
from huggingface_hub import HfApi
|
| 10 |
# Settings
|
| 11 |
+
api = HfApi()
|
| 12 |
+
|
| 13 |
MODEL_REPO_ID = "jennifee/classical_automl_model"
|
| 14 |
ZIP_FILENAME = "autogluon_predictor_dir.zip"
|
| 15 |
CACHE_DIR = pathlib.Path("hf_assets")
|
|
|
|
| 24 |
]
|
| 25 |
TARGET_COL = "sleep_quality"
|
| 26 |
# Encoding for likert questions
|
| 27 |
+
# Encoding for likert questions
|
| 28 |
LIKERT5_LABELS = ["Never", "Rarely", "Sometimes", "Often", "Very Often"]
|
| 29 |
LIKERT5_MAP = {label: idx for idx, label in enumerate(LIKERT5_LABELS)}
|
| 30 |
|
|
|
|
| 80 |
FEATURE_COLS[0]: float(phone_hours),
|
| 81 |
FEATURE_COLS[1]: float(computer_hours),
|
| 82 |
FEATURE_COLS[2]: int(device_count),
|
| 83 |
+
FEATURE_COLS[3]: int(use_before_bed_code), # Index 3 for 'use_before_bed'
|
| 84 |
+
FEATURE_COLS[4]: float(sleep_time),
|
| 85 |
+
FEATURE_COLS[5]: float(sleep_hours),
|
| 86 |
}
|
| 87 |
X = pandas.DataFrame([row], columns=[col for col in FEATURE_COLS if col != TARGET_COL]) # Exclude target column from input
|
| 88 |
|
|
|
|
| 150 |
device_count = gradio.Number(value=3, precision=0, label=FEATURE_COLS[2])
|
| 151 |
|
| 152 |
with gradio.Row():
|
| 153 |
+
use_before_bed_label = gradio.Radio(choices=LIKERT5_LABELS, value="Sometimes", label=FEATURE_COLS[3]) # Corrected index to 3
|
| 154 |
|
| 155 |
with gradio.Row():
|
| 156 |
+
sleep_time = gradio.Slider(0, 24, step=0.1, value=23.0, label=FEATURE_COLS[4]) # Corrected index to 4
|
| 157 |
+
sleep_hours = gradio.Slider(0, 12, step=0.1, value=7.0, label=FEATURE_COLS[5]) # Corrected index to 5
|
| 158 |
|
| 159 |
|
| 160 |
proba_pretty = gradio.Label(num_top_classes=2, label="Class probabilities") # Changed to 2 classes
|