import gradio as gr import model import os FEATURES = [ {"name": "Administrative", "desc": "Number of administrative pages visited", "type": "number", "min": 0, "max": 30}, {"name": "Administrative_Duration", "desc": "Total time spent on administrative pages (seconds)", "type": "number", "min": 0, "max": 40000}, {"name": "Informational", "desc": "Number of informational pages visited", "type": "number", "min": 0, "max": 24}, {"name": "Informational_Duration", "desc": "Total time spent on informational pages (seconds)", "type": "number", "min": 0, "max": 25480}, {"name": "ProductRelated", "desc": "Number of product-related pages visited", "type": "number", "min": 0, "max": 705}, {"name": "ProductRelated_Duration", "desc": "Total time spent on product-related pages (seconds)", "type": "number", "min": 0, "max": 63973}, {"name": "BounceRates", "desc": "Bounce rate value (0-1)", "type": "number", "step": 0.001, "min": 0, "max": 1}, {"name": "ExitRates", "desc": "Exit rate value (0-1)", "type": "number", "step": 0.001, "min": 0, "max": 1}, {"name": "PageValues", "desc": "Page value (0-361)", "type": "number", "step": 0.01, "min": 0, "max": 361}, {"name": "SpecialDay", "desc": "Special day proximity (0-1)", "type": "number", "step": 0.01, "min": 0, "max": 1}, {"name": "Month", "desc": "Month of the visit", "type": "select", "options": ["Jan", "Feb", "Mar", "Apr", "May", "June", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]}, {"name": "OperatingSystems", "desc": "Operating system (1-8)", "type": "number", "min": 1, "max": 8}, {"name": "Browser", "desc": "Browser (1-13)", "type": "number", "min": 1, "max": 13}, {"name": "Region", "desc": "Region (1-9)", "type": "number", "min": 1, "max": 9}, {"name": "TrafficType", "desc": "Traffic type (1-20)", "type": "number", "min": 1, "max": 20}, {"name": "VisitorType", "desc": "Type of visitor", "type": "select", "options": ["New_Visitor", "Returning_Visitor", "Other"]}, {"name": "Weekend", "desc": "Is weekend?", "type": "select", "options": ["True", "False"]}, ] # 1. Main Tab: Show metrics and images def main_tab(): metrics = """ **Model Metrics:** - Accuracy: 0.8619 - Precision: 0.5335 - Recall: 0.5497 - F1 Score: 0.5415 - ROC AUC Score: 0.7330 """ img_dir = "imgs" img_files = [ ("Classification Metrics", os.path.join(img_dir, "classification_metrics_bar_plot.png")), ("Confusion Matrix", os.path.join(img_dir, "confusion_matrix.png")), ("ROC Curve", os.path.join(img_dir, "roc_curve.png")), ] # Only return label and path for existing files img_comps = [(label, img) for label, img in img_files if os.path.exists(img)] return metrics, img_comps # 2. Dataset Tab: Show info and column descriptions def dataset_tab(): dataset_info = """ **Dataset:** [Online Shoppers Purchasing Intention Dataset](https://archive.ics.uci.edu/dataset/468/online+shoppers+purchasing+intention+dataset) - 18,000+ sessions, 17 features + target - Binary classification: Revenue (True/False) """ columns_html = """
| Column | Description | Range/Options |
|---|---|---|
| {f['name']} | {f['desc']} | {rng} |