nanye commited on
Commit
9ecb1ae
·
1 Parent(s): 8d7f3cf
Dockerfile CHANGED
@@ -2,11 +2,12 @@ FROM python:3.12
2
 
3
  WORKDIR /code
4
 
5
- COPY ./frontends/gradio/ /code
 
 
6
 
7
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
 
9
  EXPOSE 7860
10
 
11
- #CMD ["shiny", "run", "decision.py", "--host", "0.0.0.0", "--port", "7860"]
12
- CMD ["python", "gradio_eg.py"]
 
2
 
3
  WORKDIR /code
4
 
5
+ COPY app.py /code/app.py
6
+ COPY app/ /code/app/
7
+ COPY requirements.txt /code/requirements.txt
8
 
9
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
10
 
11
  EXPOSE 7860
12
 
13
+ CMD ["python", "app.py"]
 
README.md CHANGED
@@ -1,6 +1,6 @@
1
  ---
2
- title: Testbed Pythonshiny
3
- emoji: 🌍
4
  colorFrom: yellow
5
  colorTo: indigo
6
  sdk: docker
@@ -8,14 +8,134 @@ pinned: false
8
  license: mit
9
  ---
10
 
11
- This is a templated Space for [Shiny for Python](https://shiny.rstudio.com/py/).
12
 
13
- test
14
 
15
- To get started with a new app do the following:
16
 
17
- 1) Install Shiny with `pip install shiny`
18
- 2) Create a new app with `shiny create`
19
- 3) Then run the app with `shiny run --reload`
 
 
 
 
20
 
21
- To learn more about this framework please see the [Documentation](https://shiny.rstudio.com/py/docs/overview.html).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: HF Space Analytics
3
+ emoji: 📊
4
  colorFrom: yellow
5
  colorTo: indigo
6
  sdk: docker
 
8
  license: mit
9
  ---
10
 
11
+ # HF Space Analytics — Gradio Edition
12
 
13
+ A small Gradio Space that tracks page views across your other Hugging Face Spaces. Gradio provides the dashboard, while an embedded FastAPI application provides the tracking endpoints.
14
 
15
+ ## Features
16
 
17
+ - Gradio dashboard at `/`
18
+ - `POST /track` — record a page-view event
19
+ - `GET /stats` — aggregated visit counts
20
+ - `GET /events` — recent raw events
21
+ - `GET /tracker.js` — reusable browser tracker
22
+ - `GET /health` — health and storage check
23
+ - Daily JSONL storage in an attached Hugging Face Storage Bucket
24
 
25
+ ## 1. Create the analytics Space
26
+
27
+ 1. Create a new Hugging Face Space.
28
+ 2. Select **Gradio** as the SDK.
29
+ 3. Select **ZeroGPU** hardware. Dashboard refreshes use a one-second ZeroGPU allocation;
30
+ tracking and API requests remain CPU-only.
31
+ 4. Upload every file in this project, or push the repository with Git.
32
+ 5. In the Space settings, attach a Hugging Face Storage Bucket as a read-write volume mounted at `/data`.
33
+ 6. Add the optional variables and secrets below.
34
+
35
+ | Name | Type | Purpose |
36
+ |---|---|---|
37
+ | `TRACKING_KEY` | Secret | Required in tracking requests when set |
38
+ | `ADMIN_KEY` | Secret | Protects `/stats`, `/events`, and the dashboard when set |
39
+ | `ALLOWED_ORIGINS` | Variable | Comma-separated CORS origins; default `*` |
40
+ | `DATA_DIR` | Variable | Storage path; default `/data/visits` |
41
+ | `HASH_SALT` | Secret | Salt used to hash browser visitor IDs |
42
+
43
+ The top-level `app.py` starts the mounted Gradio/FastAPI application on port `7860`,
44
+ the standard port for Gradio Spaces. Do not configure a `PORT` variable for this Space;
45
+ that generic variable may be used by another process in the runtime.
46
+
47
+ ## 2. Add tracking to another Space
48
+
49
+ ### Static HTML or a custom frontend
50
+
51
+ Add this before `</body>`:
52
+
53
+ ```html
54
+ <script
55
+ src="https://YOUR-ANALYTICS-SPACE.hf.space/tracker.js"
56
+ data-endpoint="https://YOUR-ANALYTICS-SPACE.hf.space/track"
57
+ data-space="YOUR_USERNAME/YOUR_SPACE"
58
+ data-key="YOUR_TRACKING_KEY"
59
+ defer>
60
+ </script>
61
+ ```
62
+
63
+ Omit `data-key` when `TRACKING_KEY` is not configured.
64
+
65
+ ### Another Gradio Space
66
+
67
+ See [`examples/gradio_example.py`](examples/gradio_example.py). It injects the same tracker through `gr.Blocks(head=...)`.
68
+
69
+ ### Direct JavaScript
70
+
71
+ ```javascript
72
+ fetch("https://YOUR-ANALYTICS-SPACE.hf.space/track", {
73
+ method: "POST",
74
+ headers: {
75
+ "Content-Type": "application/json",
76
+ "X-Tracking-Key": "YOUR_TRACKING_KEY"
77
+ },
78
+ body: JSON.stringify({
79
+ space: "YOUR_USERNAME/YOUR_SPACE",
80
+ path: location.pathname,
81
+ referrer: document.referrer || null,
82
+ visitor_id: localStorage.getItem("hf_analytics_visitor")
83
+ }),
84
+ keepalive: true
85
+ });
86
+ ```
87
+
88
+ ## 3. Read statistics
89
+
90
+ Open the analytics Space to use the Gradio dashboard, or call the API directly:
91
+
92
+ ```bash
93
+ curl "https://YOUR-ANALYTICS-SPACE.hf.space/stats?days=30"
94
+ ```
95
+
96
+ With an admin key:
97
+
98
+ ```bash
99
+ curl -H "X-Admin-Key: YOUR_ADMIN_KEY" \
100
+ "https://YOUR-ANALYTICS-SPACE.hf.space/stats?days=30"
101
+ ```
102
+
103
+ ## Storage
104
+
105
+ The default layout is:
106
+
107
+ ```text
108
+ /data/visits/
109
+ ├── 2026-08-06.jsonl
110
+ ├── 2026-08-07.jsonl
111
+ └── ...
112
+ ```
113
+
114
+ Without a bucket mounted at `/data`, files are written to the Space filesystem and may disappear after a restart or rebuild.
115
+
116
+ ## Privacy and security
117
+
118
+ - IP addresses are not stored.
119
+ - Browser visitor IDs are salted and hashed before storage.
120
+ - Paths and referrers may contain sensitive information; omit them when unnecessary.
121
+ - `TRACKING_KEY` is visible to visitors when included in browser JavaScript. Treat it only as a low-value anti-spam key, never as a Hugging Face access token.
122
+ - Set an `ADMIN_KEY` before exposing raw events or private analytics.
123
+ - Publish an appropriate privacy notice for your users and jurisdiction.
124
+
125
+ ## Local development
126
+
127
+ ```bash
128
+ python -m venv .venv
129
+ source .venv/bin/activate
130
+ pip install -r requirements.txt
131
+ DATA_DIR=./local-data python app.py
132
+ ```
133
+
134
+ Then open `http://localhost:7860`.
135
+
136
+ Run tests:
137
+
138
+ ```bash
139
+ pip install -r requirements-dev.txt
140
+ pytest
141
+ ```
app.py CHANGED
@@ -1,162 +1,14 @@
1
- import faicons as fa
2
- import plotly.express as px
 
3
 
4
- # Load data and compute static values
5
- from shared import app_dir, tips
6
- from shinywidgets import render_plotly
7
 
8
- from shiny import reactive, render
9
- from shiny.express import input, ui
 
 
10
 
11
- bill_rng = (min(tips.total_bill), max(tips.total_bill))
12
-
13
- # Add page title and sidebar
14
- ui.page_opts(title="Restaurant tipping", fillable=True)
15
-
16
- with ui.sidebar(open="desktop"):
17
- ui.input_slider(
18
- "total_bill",
19
- "Bill amount",
20
- min=bill_rng[0],
21
- max=bill_rng[1],
22
- value=bill_rng,
23
- pre="$",
24
- )
25
- ui.input_checkbox_group(
26
- "time",
27
- "Food service",
28
- ["Lunch", "Dinner"],
29
- selected=["Lunch", "Dinner"],
30
- inline=True,
31
- )
32
- ui.input_action_button("reset", "Reset filter")
33
-
34
- # Add main content
35
- ICONS = {
36
- "user": fa.icon_svg("user", "regular"),
37
- "wallet": fa.icon_svg("wallet"),
38
- "currency-dollar": fa.icon_svg("dollar-sign"),
39
- "ellipsis": fa.icon_svg("ellipsis"),
40
- }
41
-
42
- with ui.layout_columns(fill=False):
43
- with ui.value_box(showcase=ICONS["user"]):
44
- "Total tippers"
45
-
46
- @render.express
47
- def total_tippers():
48
- tips_data().shape[0]
49
-
50
- with ui.value_box(showcase=ICONS["wallet"]):
51
- "Average tip"
52
-
53
- @render.express
54
- def average_tip():
55
- d = tips_data()
56
- if d.shape[0] > 0:
57
- perc = d.tip / d.total_bill
58
- f"{perc.mean():.1%}"
59
-
60
- with ui.value_box(showcase=ICONS["currency-dollar"]):
61
- "Average bill"
62
-
63
- @render.express
64
- def average_bill():
65
- d = tips_data()
66
- if d.shape[0] > 0:
67
- bill = d.total_bill.mean()
68
- f"${bill:.2f}"
69
-
70
-
71
- with ui.layout_columns(col_widths=[6, 6, 12]):
72
- with ui.card(full_screen=True):
73
- ui.card_header("Tips data")
74
-
75
- @render.data_frame
76
- def table():
77
- return render.DataGrid(tips_data())
78
-
79
- with ui.card(full_screen=True):
80
- with ui.card_header(class_="d-flex justify-content-between align-items-center"):
81
- "Total bill vs tip"
82
- with ui.popover(title="Add a color variable", placement="top"):
83
- ICONS["ellipsis"]
84
- ui.input_radio_buttons(
85
- "scatter_color",
86
- None,
87
- ["none", "sex", "smoker", "day", "time"],
88
- inline=True,
89
- )
90
-
91
- @render_plotly
92
- def scatterplot():
93
- color = input.scatter_color()
94
- return px.scatter(
95
- tips_data(),
96
- x="total_bill",
97
- y="tip",
98
- color=None if color == "none" else color,
99
- trendline="lowess",
100
- )
101
-
102
- with ui.card(full_screen=True):
103
- with ui.card_header(class_="d-flex justify-content-between align-items-center"):
104
- "Tip percentages"
105
- with ui.popover(title="Add a color variable"):
106
- ICONS["ellipsis"]
107
- ui.input_radio_buttons(
108
- "tip_perc_y",
109
- "Split by:",
110
- ["sex", "smoker", "day", "time"],
111
- selected="day",
112
- inline=True,
113
- )
114
-
115
- @render_plotly
116
- def tip_perc():
117
- from ridgeplot import ridgeplot
118
-
119
- dat = tips_data()
120
- dat["percent"] = dat.tip / dat.total_bill
121
- yvar = input.tip_perc_y()
122
- uvals = dat[yvar].unique()
123
-
124
- samples = [[dat.percent[dat[yvar] == val]] for val in uvals]
125
-
126
- plt = ridgeplot(
127
- samples=samples,
128
- labels=uvals,
129
- bandwidth=0.01,
130
- colorscale="viridis",
131
- colormode="row-index",
132
- )
133
-
134
- plt.update_layout(
135
- legend=dict(
136
- orientation="h", yanchor="bottom", y=1.02, xanchor="center", x=0.5
137
- )
138
- )
139
-
140
- return plt
141
-
142
-
143
- ui.include_css(app_dir / "styles.css")
144
-
145
- # --------------------------------------------------------
146
- # Reactive calculations and effects
147
- # --------------------------------------------------------
148
-
149
-
150
- @reactive.calc
151
- def tips_data():
152
- bill = input.total_bill()
153
- idx1 = tips.total_bill.between(bill[0], bill[1])
154
- idx2 = tips.time.isin(input.time())
155
- return tips[idx1 & idx2]
156
-
157
-
158
- @reactive.effect
159
- @reactive.event(input.reset)
160
- def _():
161
- ui.update_slider("total_bill", value=bill_rng)
162
- ui.update_checkbox_group("time", selected=["Lunch", "Dinner"])
 
1
+ import uvicorn
2
+ #import torch
3
+ #import spaces
4
 
5
+ from app.main import app
 
 
6
 
7
+ #@spaces.GPU
8
+ #def init():
9
+ #x = torch.randn(256, 256, device="cuda")
10
+ #print(x.sum())
11
 
12
+ if __name__ == "__main__":
13
+ #init()
14
+ uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/__init__.py ADDED
File without changes
app/main.py ADDED
@@ -0,0 +1,309 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import hashlib
4
+ import hmac
5
+ import json
6
+ import os
7
+ import threading
8
+ from collections import Counter
9
+ from datetime import timezone, date, datetime, timedelta
10
+ from pathlib import Path
11
+ from typing import Annotated, Any
12
+
13
+ import gradio as gr
14
+ #import spaces
15
+ #import torch
16
+
17
+ #try:
18
+ #import spaces
19
+ #except ImportError:
20
+ ## The `spaces` package is injected by the Hugging Face ZeroGPU runtime.
21
+ ## Keep local development and CPU-based tests usable without that runtime.
22
+ #class _SpacesFallback:
23
+ #@staticmethod
24
+ #def GPU(*_args, **_kwargs):
25
+ #def decorator(function):
26
+ #return function
27
+
28
+ #return decorator
29
+
30
+ #spaces = _SpacesFallback()
31
+
32
+ from fastapi import FastAPI, Header, HTTPException, Query, Request
33
+ from fastapi.middleware.cors import CORSMiddleware
34
+ from fastapi.responses import Response
35
+ from pydantic import BaseModel, ConfigDict, Field, field_validator
36
+
37
+ APP_TITLE = "HF Space Analytics"
38
+ DATA_DIR = Path(os.getenv("DATA_DIR", "/data/visits"))
39
+ TRACKING_KEY = os.getenv("TRACKING_KEY", "")
40
+ ADMIN_KEY = os.getenv("ADMIN_KEY", "")
41
+ HASH_SALT = os.getenv("HASH_SALT", "change-this-salt")
42
+ MAX_FIELD_LENGTH = 500
43
+ WRITE_LOCK = threading.Lock()
44
+
45
+ DATA_DIR.mkdir(parents=True, exist_ok=True)
46
+
47
+ origins_raw = os.getenv("ALLOWED_ORIGINS", "*")
48
+ ALLOWED_ORIGINS = [x.strip() for x in origins_raw.split(",") if x.strip()]
49
+
50
+ api = FastAPI(title=APP_TITLE, version="2.0.0")
51
+ api.add_middleware(
52
+ CORSMiddleware,
53
+ allow_origins=ALLOWED_ORIGINS,
54
+ allow_credentials=False,
55
+ allow_methods=["GET", "POST", "OPTIONS"],
56
+ allow_headers=["Content-Type", "X-Tracking-Key", "X-Admin-Key"],
57
+ )
58
+
59
+
60
+ class TrackEvent(BaseModel):
61
+ model_config = ConfigDict(extra="ignore", str_strip_whitespace=True)
62
+
63
+ space: str = Field(min_length=1, max_length=200)
64
+ path: str | None = Field(default=None, max_length=MAX_FIELD_LENGTH)
65
+ referrer: str | None = Field(default=None, max_length=MAX_FIELD_LENGTH)
66
+ visitor_id: str | None = Field(default=None, max_length=200)
67
+ event: str = Field(default="page_view", min_length=1, max_length=100)
68
+
69
+ @field_validator("space")
70
+ @classmethod
71
+ def validate_space(cls, value: str) -> str:
72
+ if any(c in value for c in "\r\n\t"):
73
+ raise ValueError("space contains invalid control characters")
74
+ return value
75
+
76
+
77
+ def secure_equal(provided: str | None, expected: str) -> bool:
78
+ return bool(provided) and hmac.compare_digest(provided, expected)
79
+
80
+
81
+ def require_tracking_key(key: str | None) -> None:
82
+ if TRACKING_KEY and not secure_equal(key, TRACKING_KEY):
83
+ raise HTTPException(status_code=401, detail="Invalid tracking key")
84
+
85
+
86
+ def require_admin_key(key: str | None) -> None:
87
+ if ADMIN_KEY and not secure_equal(key, ADMIN_KEY):
88
+ raise HTTPException(status_code=401, detail="Invalid admin key")
89
+
90
+
91
+ def hash_visitor(visitor_id: str | None) -> str | None:
92
+ if not visitor_id:
93
+ return None
94
+ digest = hashlib.sha256(f"{HASH_SALT}:{visitor_id}".encode()).hexdigest()
95
+ return digest[:32]
96
+
97
+
98
+ def daily_file(day: date) -> Path:
99
+ return DATA_DIR / f"{day.isoformat()}.jsonl"
100
+
101
+
102
+ def append_event(record: dict[str, Any]) -> None:
103
+ path = daily_file(datetime.now(timezone.utc).date())
104
+ line = json.dumps(record, ensure_ascii=False, separators=(",", ":")) + "\n"
105
+ with WRITE_LOCK:
106
+ with path.open("a", encoding="utf-8") as handle:
107
+ handle.write(line)
108
+ handle.flush()
109
+ os.fsync(handle.fileno())
110
+
111
+
112
+ def iter_events(days: int):
113
+ today = datetime.now(timezone.utc).date()
114
+ for offset in range(days - 1, -1, -1):
115
+ path = daily_file(today - timedelta(days=offset))
116
+ if not path.exists():
117
+ continue
118
+ try:
119
+ with path.open("r", encoding="utf-8") as handle:
120
+ for line in handle:
121
+ try:
122
+ yield json.loads(line)
123
+ except json.JSONDecodeError:
124
+ continue
125
+ except OSError:
126
+ continue
127
+
128
+
129
+ def calculate_stats(days: int, space: str | None = None) -> dict[str, Any]:
130
+ events = [
131
+ row
132
+ for row in iter_events(days)
133
+ if row.get("event") == "page_view" and (space is None or row.get("space") == space)
134
+ ]
135
+ by_space = Counter(str(row.get("space", "unknown")) for row in events)
136
+ by_day = Counter(str(row.get("date", "unknown")) for row in events)
137
+ unique_visitors = {row["visitor_hash"] for row in events if row.get("visitor_hash")}
138
+ return {
139
+ "period_days": days,
140
+ "space_filter": space,
141
+ "page_views": len(events),
142
+ "unique_visitors": len(unique_visitors),
143
+ "by_space": dict(sorted(by_space.items())),
144
+ "by_day": dict(sorted(by_day.items())),
145
+ }
146
+
147
+
148
+ @api.get("/health")
149
+ def health() -> dict[str, Any]:
150
+ return {
151
+ "status": "ok",
152
+ "storage_path": str(DATA_DIR),
153
+ "storage_writable": os.access(DATA_DIR, os.W_OK),
154
+ }
155
+
156
+
157
+ @api.post("/track", status_code=202)
158
+ def track(
159
+ event: TrackEvent,
160
+ request: Request,
161
+ x_tracking_key: Annotated[str | None, Header()] = None,
162
+ ) -> dict[str, str]:
163
+ require_tracking_key(x_tracking_key)
164
+ now = datetime.now(timezone.utc)
165
+ append_event(
166
+ {
167
+ "timestamp": now.isoformat(),
168
+ "date": now.date().isoformat(),
169
+ "space": event.space,
170
+ "path": event.path,
171
+ "referrer": event.referrer,
172
+ "visitor_hash": hash_visitor(event.visitor_id),
173
+ "event": event.event,
174
+ "user_agent": request.headers.get("user-agent", "")[:MAX_FIELD_LENGTH] or None,
175
+ }
176
+ )
177
+ return {"status": "accepted"}
178
+
179
+
180
+ @api.get("/stats")
181
+ def stats(
182
+ days: Annotated[int, Query(ge=1, le=366)] = 30,
183
+ space: Annotated[str | None, Query(max_length=200)] = None,
184
+ x_admin_key: Annotated[str | None, Header()] = None,
185
+ ) -> dict[str, Any]:
186
+ require_admin_key(x_admin_key)
187
+ return calculate_stats(days, space)
188
+
189
+
190
+ @api.get("/events")
191
+ def recent_events(
192
+ days: Annotated[int, Query(ge=1, le=30)] = 1,
193
+ limit: Annotated[int, Query(ge=1, le=1000)] = 100,
194
+ x_admin_key: Annotated[str | None, Header()] = None,
195
+ ) -> dict[str, Any]:
196
+ require_admin_key(x_admin_key)
197
+ rows = list(iter_events(days))[-limit:]
198
+ return {"count": len(rows), "events": rows}
199
+
200
+
201
+ TRACKER_JS = r"""
202
+ (() => {
203
+ const script = document.currentScript;
204
+ if (!script) return;
205
+ const endpoint = script.dataset.endpoint;
206
+ const space = script.dataset.space || window.location.hostname;
207
+ const key = script.dataset.key || "";
208
+ if (!endpoint) return;
209
+
210
+ const storageKey = "hf_analytics_visitor";
211
+ let visitorId = null;
212
+ try {
213
+ visitorId = localStorage.getItem(storageKey);
214
+ if (!visitorId) {
215
+ visitorId = globalThis.crypto?.randomUUID?.() ||
216
+ `${Date.now()}-${Math.random().toString(36).slice(2)}`;
217
+ localStorage.setItem(storageKey, visitorId);
218
+ }
219
+ } catch (_) {}
220
+
221
+ const headers = {"Content-Type": "application/json"};
222
+ if (key) headers["X-Tracking-Key"] = key;
223
+
224
+ fetch(endpoint, {
225
+ method: "POST",
226
+ headers,
227
+ body: JSON.stringify({
228
+ space,
229
+ path: window.location.pathname,
230
+ referrer: document.referrer || null,
231
+ visitor_id: visitorId,
232
+ event: "page_view"
233
+ }),
234
+ keepalive: true,
235
+ mode: "cors",
236
+ credentials: "omit"
237
+ }).catch(() => {});
238
+ })();
239
+ """
240
+
241
+
242
+ @api.get("/tracker.js")
243
+ def tracker_js() -> Response:
244
+ return Response(
245
+ TRACKER_JS,
246
+ media_type="application/javascript",
247
+ headers={"Cache-Control": "public, max-age=300"},
248
+ )
249
+
250
+
251
+ #@spaces.GPU(duration=1)
252
+ def dashboard_stats(days: int, space: str, admin_key: str):
253
+ #if not torch.cuda.is_available():
254
+ #raise RuntimeError("CUDA GPU is unavailable")
255
+
256
+ #x = torch.randn(256, 256, device="cuda")
257
+ #result = x @ x
258
+ #torch.cuda.synchronize()
259
+
260
+ #print(
261
+ #f"GPU computation completed: "
262
+ #f"{torch.cuda.get_device_name(0)}, device={result.device}",
263
+ #flush=True,
264
+ #)
265
+
266
+ try:
267
+ require_admin_key(admin_key or None)
268
+ days = max(1, min(int(days), 366))
269
+ result = calculate_stats(days, space.strip() or None)
270
+ by_space = [[name, count] for name, count in sorted(
271
+ result["by_space"].items(), key=lambda item: item[1], reverse=True
272
+ )]
273
+ by_day = [[day, count] for day, count in result["by_day"].items()]
274
+ status = f"Showing the last {days} day(s)."
275
+ return result["page_views"], result["unique_visitors"], by_space, by_day, status
276
+ except HTTPException:
277
+ raise gr.Error("Invalid admin key")
278
+ except Exception as exc:
279
+ raise gr.Error(f"Could not load statistics: {exc}") from exc
280
+
281
+
282
+ with gr.Blocks(title=APP_TITLE) as demo:
283
+ gr.Markdown(
284
+ "# 📊 HF Space Analytics\n"
285
+ "Minimal page-view analytics stored in an attached Hugging Face Storage Bucket."
286
+ )
287
+ with gr.Row():
288
+ days_input = gr.Number(value=30, minimum=1, maximum=366, precision=0, label="Days")
289
+ space_input = gr.Textbox(label="Space filter", placeholder="Optional: username/space")
290
+ admin_input = gr.Textbox(label="Admin key", type="password", placeholder="Only if configured")
291
+ load_button = gr.Button("Load statistics", variant="primary")
292
+ status_output = gr.Markdown()
293
+ with gr.Row():
294
+ views_output = gr.Number(label="Page views", interactive=False)
295
+ visitors_output = gr.Number(label="Unique visitors", interactive=False)
296
+ gr.Markdown("## Views by Space")
297
+ spaces_output = gr.Dataframe(headers=["Space", "Views"], datatype=["str", "number"], interactive=False)
298
+ gr.Markdown("## Views by Day")
299
+ days_output = gr.Dataframe(headers=["Date", "Views"], datatype=["str", "number"], interactive=False)
300
+
301
+ load_button.click(
302
+ dashboard_stats,
303
+ inputs=[days_input, space_input, admin_input],
304
+ outputs=[views_output, visitors_output, spaces_output, days_output, status_output],
305
+ api_name=False,
306
+ )
307
+
308
+ # Custom API routes are registered first; Gradio is mounted last at the root.
309
+ app = gr.mount_gradio_app(api, demo, path="/")
decision.py DELETED
@@ -1,310 +0,0 @@
1
- import numpy as np
2
-
3
- import plotly.express as px
4
- import plotly.graph_objects as go
5
-
6
- from sklearn.datasets import make_moons
7
- from sklearn.linear_model import LogisticRegression
8
- from sklearn.svm import LinearSVC
9
- from sklearn.ensemble import RandomForestClassifier
10
-
11
- from shiny import App, ui, reactive, render
12
- from shinywidgets import render_plotly, output_widget, render_widget
13
-
14
- import logging
15
- logging.basicConfig(
16
- level=logging.INFO, # set minimum level to capture (DEBUG, INFO, WARNING, ERROR, CRITICAL)
17
- format="%(asctime)s [%(levelname)s] %(message)s", # log format
18
- )
19
- logger = logging.getLogger("ELVIS")
20
-
21
- X, y = make_moons(noise=0.25, random_state=0)
22
- model = LogisticRegression().fit(X, y)
23
- print(y)
24
-
25
- #with ui.sidebar():
26
- #ui.input_slider(
27
- #"grid_resolution",
28
- #"Grid resolution",
29
- #min=50,
30
- #max=400,
31
- #value=200,
32
- #step=25,
33
- #)
34
-
35
- #ui.input_slider(
36
- #"marker_size",
37
- #"Marker size",
38
- #min=4,
39
- #max=20,
40
- #value=8,
41
- #)
42
-
43
- #ui.input_action_button("reset", "Reset")
44
-
45
- app_ui = ui.page_fluid(
46
- ui.include_css("styles.css"),
47
- ui.layout_columns(
48
- # first column
49
- ui.card(style="border: none !important; box-shadow: none !important;"),
50
- # second column
51
- ui.markdown("""
52
- # Decision Boundary Visualizer
53
- """),
54
- col_widths=[1, 11]
55
- ),
56
- ui.layout_columns(
57
- #ui.card(class_="card-no-border"),
58
- ui.card(style="border: none !important; box-shadow: none !important;"),
59
- ui.card(output_widget("decision_plot")), #hover=True)),
60
- ui.card(ui.navset_tab(
61
- ui.nav_panel("Dataset",
62
- ui.input_radio_buttons(
63
- "dataset",
64
- "Dataset type",
65
- {
66
- "a": "Draw2D",
67
- "b": "Upload",
68
- "c": "sklearn",},
69
- inline=True,
70
- ),
71
- ui.input_radio_buttons(
72
- "pointlabel_choice",
73
- "Choose point label",
74
- {
75
- "a": "Gray",
76
- "b": "Orange",
77
- "c": "Blue",},
78
- inline=True,
79
- ),
80
- ),
81
- ui.nav_panel("Classifier",
82
- ui.input_select(
83
- "classifier", # input ID
84
- "Select classifier:", # label displayed above the dropdown
85
- {"LinearSVC": "LinearSVC",
86
- "RandomForestClassifier": "RandomForestClassifier", "LogisticRegression": "LogisticRegression"}, # choices: value: label
87
- selected="LinearSVC" # optional default selected value
88
- ),
89
- ),
90
- ui.nav_panel("Export", ui.p("This is the table tab")),
91
- ui.nav_panel("Options", ui.p("This is the table tab")),
92
- ui.nav_panel("Usage", ui.markdown(''.join(open('usage.md', 'r').readlines()))),
93
- )),
94
- ui.card(class_="card-no-border"),
95
- col_widths=[1, 6, 4, 1])
96
- )
97
-
98
- def server(input, output, session):
99
- @reactive.calc
100
- def decision_data():
101
- #res = input.grid_resolution()
102
- res = 200
103
-
104
- x_min, x_max = X[:, 0].min() - 0.5, X[:, 0].max() + 0.5
105
- y_min, y_max = X[:, 1].min() - 0.5, X[:, 1].max() + 0.5
106
-
107
- xx, yy = np.meshgrid(
108
- np.linspace(x_min, x_max, res),
109
- np.linspace(y_min, y_max, res),
110
- )
111
-
112
- Z = model.predict(np.c_[xx.ravel(), yy.ravel()])
113
- Z = Z.reshape(xx.shape)
114
-
115
- return xx, yy, Z
116
-
117
- @output
118
- @render_widget
119
- def decision_plot():
120
- print('here')
121
- xx, yy, Z = decision_data()
122
-
123
- color = ['blue' if p == 1 else 'red' for p in y]
124
- fig = px.scatter(
125
- x=X[:, 0],
126
- y=X[:, 1],
127
- #marker=dict(color=color),
128
- color=color,
129
- )
130
-
131
- #fig.update_layout(
132
- #xaxis_title="x1",
133
- #yaxis_title="x2",
134
- #showlegend=False,
135
- #)
136
- print(input.classifier())
137
- if input.classifier() == "LogisticRegression":
138
- model = LogisticRegression() #self.model_class(**parse_param_string(self.model_args))
139
- if input.classifier() == "LinearSVC":
140
- model = LinearSVC()
141
- if input.classifier() == "RandomForestClassifier":
142
- model = RandomForestClassifier()
143
- logger.info("Fitting model " + str(model))
144
- model.fit(X, y)
145
-
146
- # plot decision boundary in the projected space
147
- # xx, yy = np.meshgrid(np.linspace(Z[:, 0].min(), 1, 100), np.linspace(0, 1, 100))
148
- # Note: Should not apply normalization/jittering to meshgrid points
149
- num_dots = 100
150
- xx, yy = np.meshgrid(np.linspace(X[:, 0].min(), X[:, 0].max(), num_dots),
151
- np.linspace(X[:, 1].min(), X[:, 1].max(), num_dots))
152
-
153
- #logger.info("grid_x shape = " + str(xx.shape) + "; grid_y shape =" + str(yy.shape))
154
- grid = np.c_[xx.ravel(), yy.ravel()]
155
- #scores = clf.decision_function(grid)[:, 1].reshape(xx.shape)
156
- #scores = clf.decision_function(grid).reshape(xx.shape)
157
- #ax.contour(xx, yy, scores)#, levels=[0], colors="black", linestyles="--")
158
- print('grid', grid)
159
- #print('inverse', embedder.inverse_transform(grid))
160
- #preds = model.predict(embedder.inverse_transform(grid)).reshape(xx.shape)
161
- preds = model.predict(grid)
162
- #print(preds.shape, xx.shape, yy.shape)
163
- color = ['blue' if p == 1 else 'red' for p in preds]
164
- fig.add_trace(
165
- go.Scatter(
166
- x=xx.ravel(),
167
- y=yy.ravel(),
168
- mode='markers', # 'lines', 'markers', 'lines+markers'
169
- #color=preds,
170
- marker=dict(color=color, size=1),
171
- #line=dict(color='orange', width=2, dash='dash') # optional style
172
- )
173
- )
174
- #ax.scatter(xx.ravel(), yy.ravel(), c=[l2c[l] for l in preds.ravel()], s=1, alpha=0.5)
175
-
176
- return fig
177
-
178
- #def decision_plot1(): #decision_boundary=False, save_figure=False):
179
- #'''
180
- #Plot data and decision boundary with matplotlib and return as PIL image.
181
- #'''
182
-
183
- #logger.info("Initializing figure")
184
- ##fig = plt.figure(figsize=(self.canvas_width/100., self.canvas_height/100.0), dpi=self.dpi)
185
- #fig = plt.figure()
186
- ## set entire figure to be the canvas to allow simple conversion of mouse
187
- ## position to coordinates in the figure
188
- #ax = fig.add_axes([0., 0., 1., 1.]) #
189
- #ax.margins(x=0, y=0) # no padding in both directions
190
-
191
- ##if self.dataset_type == 'Draw2D':
192
- ### draw canvas boundary
193
- ###ax.scatter([0, 0, 1, 1], [0, 1, 0, 1], color='brown')
194
- ### DO NOT CHANGE THE COLOR OF THE BOUNDARY
195
- ### IT WILL BREAK THE ORIGIN COORDINATE DETECTION
196
- ##ax.plot([0, 0, 1, 1, 0], [0, 1, 1, 0, 0], color='black')
197
-
198
- ##for spine in ax.spines.values():
199
- ##spine.set_color((0.1, 0.1, 0.1))
200
-
201
- ## TODO: allow showing x and y axes with ticks and labels
202
- #if (self.dataset is not None and len(self.dataset) > 0):
203
- #try:
204
- #X = self._get_features()
205
- #y = self.dataset.target.values
206
- #logger.info("Data:\n" + str(X))
207
- #logger.info("Target:\n" + str(y))
208
-
209
- ## preprocess features
210
- #X = self._process_features(X)
211
-
212
- ## embed features to 2D for visualization
213
- #Z, embedder = self._embed_features(X, return_embedder=True)
214
-
215
- ##ax.set_title("Click to add points")
216
- #labels = np.unique(y)
217
- #colors = label2color(labels, cmap=self.cmap)
218
- #logger.info("Classes:\n" + str(labels))
219
- #logger.info("Colors:\n" + str(colors))
220
- #l2c = dict(zip(labels, colors))
221
-
222
- ## scatter plots for data
223
- #for l, label in enumerate(labels):
224
- ##print('class', label)
225
- ##ax.scatter(*zip(*self.dataset[self.dataset.label == label].features), color=label, label=label)
226
- #subset = Z[y == label]
227
- #ax.scatter(subset[:, 0], subset[:, 1], color=colors[l], label=label, s=self.marker_size)
228
- #ax.legend()
229
-
230
- ## plot the decision boundary
231
- #if decision_boundary:
232
- #model = self.model_class(**parse_param_string(self.model_args))
233
- #logger.info("Fitting model " + str(model))
234
- #model.fit(X, y)
235
- #self.model = model
236
-
237
- ## plot decision boundary in the projected space
238
- ## xx, yy = np.meshgrid(np.linspace(Z[:, 0].min(), 1, 100), np.linspace(0, 1, 100))
239
- ## Note: Should not apply normalization/jittering to meshgrid points
240
- #if self.dataset_type == 'Draw2D':
241
- #xx, yy = np.meshgrid(np.linspace(0, 1, self.num_dots),
242
- #np.linspace(0, 1, self.num_dots))
243
- #else:
244
- #xx, yy = np.meshgrid(np.linspace(Z[:, 0].min(), Z[:, 0].max(), self.num_dots),
245
- #np.linspace(Z[:, 1].min(), Z[:, 1].max(), self.num_dots))
246
-
247
- ##logger.info("grid_x shape = " + str(xx.shape) + "; grid_y shape =" + str(yy.shape))
248
- #grid = np.c_[xx.ravel(), yy.ravel()]
249
- ##scores = clf.decision_function(grid)[:, 1].reshape(xx.shape)
250
- ##scores = clf.decision_function(grid).reshape(xx.shape)
251
- ##ax.contour(xx, yy, scores)#, levels=[0], colors="black", linestyles="--")
252
- #print('grid', grid)
253
- #print('inverse', embedder.inverse_transform(grid))
254
- #preds = model.predict(embedder.inverse_transform(grid)).reshape(xx.shape)
255
- ##print(preds.shape, xx.shape, yy.shape)
256
- #ax.scatter(xx.ravel(), yy.ravel(), c=[l2c[l] for l in preds.ravel()], s=1, alpha=0.5)
257
-
258
- #except Exception as e:
259
- #print(traceback.format_exc())
260
- ##raise gr.Error(f"⚠️ {e}")
261
- #gr.Info(f"⚠️ {e}")
262
-
263
- #buf = io.BytesIO()
264
- #ax.figure.savefig(buf, format="png", bbox_inches="tight", pad_inches=0)
265
- #plt.close(fig)
266
- #buf.seek(0)
267
- #img = Image.open(buf)
268
-
269
- #if save_figure:
270
- #ax.figure.savefig(f"{self.FIGURE_BASENAME}{self.figure_extension}")
271
-
272
- ## detect axis pixel positions
273
- #if self.dataset_type == 'Draw2D':
274
- #array = np.array(img.convert("RGB"))
275
- #bgr = cv2.cvtColor(array, cv2.COLOR_RGB2BGR)
276
- #gray = cv2.cvtColor(bgr, cv2.COLOR_BGR2GRAY)
277
- #black_mask = gray < 0.05 * 255
278
- #contours, _ = cv2.findContours(black_mask.astype(np.uint8), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
279
-
280
- ## find the contour with the largest area
281
- #max_area = 0
282
- #most_likely_topleft = 0, 0
283
- #for contour in contours:
284
- #x, y, w, h = cv2.boundingRect(contour)
285
- #area = w * h
286
- #if w * h > max_area:
287
- #max_area = area
288
- #most_likely_topleft = x, y
289
-
290
- #self._axis_topleft = most_likely_topleft
291
- #else:
292
- #self._axis_topleft = 0, 0
293
-
294
- ## TODO: add a save function for saving screenshot
295
- ##img.save('image.png')
296
-
297
- #return img
298
-
299
- # --------------------------------------------------
300
- # Reset logic
301
- # --------------------------------------------------
302
-
303
- #@reactive.effect
304
- #@reactive.event(input.reset)
305
- #def _():
306
- ##ui.update_slider("grid_resolution", value=200)
307
- ##ui.update_slider("marker_size", value=8)
308
- #pass
309
-
310
- app = App(app_ui, server)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontends/gradio/Dockerfile DELETED
@@ -1,14 +0,0 @@
1
- FROM python:3.12
2
-
3
- WORKDIR /code
4
-
5
- COPY ./frontends/gradio/requirements.txt /code/requirements.txt
6
-
7
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
-
9
- COPY . .
10
-
11
- EXPOSE 7860
12
-
13
- #CMD ["shiny", "run", "decision.py", "--host", "0.0.0.0", "--port", "7860"]
14
- CMD ["python", "gradio_eg.py", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontends/gradio/gradio_eg.py DELETED
@@ -1,10 +0,0 @@
1
- import gradio as gr
2
-
3
- with gr.Blocks() as demo:
4
- gr.Markdown("# My Gradio App")
5
-
6
- #demo.launch()
7
- demo.launch(server_name="0.0.0.0", server_port=7860)
8
- #demo.launch(server_name="0.0.0.0", server_port=8765)
9
-
10
-
 
 
 
 
 
 
 
 
 
 
 
frontends/gradio/requirements.txt DELETED
@@ -1 +0,0 @@
1
- gradio
 
 
frontends/shiny/Dockerfile DELETED
@@ -1,14 +0,0 @@
1
- FROM python:3.12
2
-
3
- WORKDIR /code
4
-
5
- COPY ./requirements.txt /code/requirements.txt
6
-
7
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
-
9
- COPY . .
10
-
11
- EXPOSE 7860
12
-
13
- #CMD ["shiny", "run", "decision.py", "--host", "0.0.0.0", "--port", "7860"]
14
- CMD ["python", "gradio_eg.py", "--host", "0.0.0.0", "--port", "7860"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
frontends/shiny/requirements.txt DELETED
@@ -1,6 +0,0 @@
1
- faicons
2
- shiny
3
- shinywidgets
4
- plotly
5
- pandas
6
- ridgeplot
 
 
 
 
 
 
 
gradio_eg.py DELETED
@@ -1,10 +0,0 @@
1
- import gradio as gr
2
-
3
- with gr.Blocks() as demo:
4
- gr.Markdown("# My Gradio App")
5
-
6
- #demo.launch()
7
- demo.launch(server_name="0.0.0.0", server_port=7860)
8
- #demo.launch(server_name="0.0.0.0", server_port=8765)
9
-
10
-
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
- faicons
2
- shiny
3
- shinywidgets
4
- plotly
5
- pandas
6
- ridgeplot
 
1
+ gradio>=5.35,<7
2
+ fastapi>=0.115,<1
3
+ uvicorn[standard]>=0.30,<1
4
+ pydantic>=2.8,<3
5
+ spaces
6
+ torch
shared.py DELETED
@@ -1,6 +0,0 @@
1
- from pathlib import Path
2
-
3
- import pandas as pd
4
-
5
- app_dir = Path(__file__).parent
6
- tips = pd.read_csv(app_dir / "tips.csv")
 
 
 
 
 
 
 
tips.csv DELETED
@@ -1,245 +0,0 @@
1
- total_bill,tip,sex,smoker,day,time,size
2
- 16.99,1.01,Female,No,Sun,Dinner,2
3
- 10.34,1.66,Male,No,Sun,Dinner,3
4
- 21.01,3.5,Male,No,Sun,Dinner,3
5
- 23.68,3.31,Male,No,Sun,Dinner,2
6
- 24.59,3.61,Female,No,Sun,Dinner,4
7
- 25.29,4.71,Male,No,Sun,Dinner,4
8
- 8.77,2.0,Male,No,Sun,Dinner,2
9
- 26.88,3.12,Male,No,Sun,Dinner,4
10
- 15.04,1.96,Male,No,Sun,Dinner,2
11
- 14.78,3.23,Male,No,Sun,Dinner,2
12
- 10.27,1.71,Male,No,Sun,Dinner,2
13
- 35.26,5.0,Female,No,Sun,Dinner,4
14
- 15.42,1.57,Male,No,Sun,Dinner,2
15
- 18.43,3.0,Male,No,Sun,Dinner,4
16
- 14.83,3.02,Female,No,Sun,Dinner,2
17
- 21.58,3.92,Male,No,Sun,Dinner,2
18
- 10.33,1.67,Female,No,Sun,Dinner,3
19
- 16.29,3.71,Male,No,Sun,Dinner,3
20
- 16.97,3.5,Female,No,Sun,Dinner,3
21
- 20.65,3.35,Male,No,Sat,Dinner,3
22
- 17.92,4.08,Male,No,Sat,Dinner,2
23
- 20.29,2.75,Female,No,Sat,Dinner,2
24
- 15.77,2.23,Female,No,Sat,Dinner,2
25
- 39.42,7.58,Male,No,Sat,Dinner,4
26
- 19.82,3.18,Male,No,Sat,Dinner,2
27
- 17.81,2.34,Male,No,Sat,Dinner,4
28
- 13.37,2.0,Male,No,Sat,Dinner,2
29
- 12.69,2.0,Male,No,Sat,Dinner,2
30
- 21.7,4.3,Male,No,Sat,Dinner,2
31
- 19.65,3.0,Female,No,Sat,Dinner,2
32
- 9.55,1.45,Male,No,Sat,Dinner,2
33
- 18.35,2.5,Male,No,Sat,Dinner,4
34
- 15.06,3.0,Female,No,Sat,Dinner,2
35
- 20.69,2.45,Female,No,Sat,Dinner,4
36
- 17.78,3.27,Male,No,Sat,Dinner,2
37
- 24.06,3.6,Male,No,Sat,Dinner,3
38
- 16.31,2.0,Male,No,Sat,Dinner,3
39
- 16.93,3.07,Female,No,Sat,Dinner,3
40
- 18.69,2.31,Male,No,Sat,Dinner,3
41
- 31.27,5.0,Male,No,Sat,Dinner,3
42
- 16.04,2.24,Male,No,Sat,Dinner,3
43
- 17.46,2.54,Male,No,Sun,Dinner,2
44
- 13.94,3.06,Male,No,Sun,Dinner,2
45
- 9.68,1.32,Male,No,Sun,Dinner,2
46
- 30.4,5.6,Male,No,Sun,Dinner,4
47
- 18.29,3.0,Male,No,Sun,Dinner,2
48
- 22.23,5.0,Male,No,Sun,Dinner,2
49
- 32.4,6.0,Male,No,Sun,Dinner,4
50
- 28.55,2.05,Male,No,Sun,Dinner,3
51
- 18.04,3.0,Male,No,Sun,Dinner,2
52
- 12.54,2.5,Male,No,Sun,Dinner,2
53
- 10.29,2.6,Female,No,Sun,Dinner,2
54
- 34.81,5.2,Female,No,Sun,Dinner,4
55
- 9.94,1.56,Male,No,Sun,Dinner,2
56
- 25.56,4.34,Male,No,Sun,Dinner,4
57
- 19.49,3.51,Male,No,Sun,Dinner,2
58
- 38.01,3.0,Male,Yes,Sat,Dinner,4
59
- 26.41,1.5,Female,No,Sat,Dinner,2
60
- 11.24,1.76,Male,Yes,Sat,Dinner,2
61
- 48.27,6.73,Male,No,Sat,Dinner,4
62
- 20.29,3.21,Male,Yes,Sat,Dinner,2
63
- 13.81,2.0,Male,Yes,Sat,Dinner,2
64
- 11.02,1.98,Male,Yes,Sat,Dinner,2
65
- 18.29,3.76,Male,Yes,Sat,Dinner,4
66
- 17.59,2.64,Male,No,Sat,Dinner,3
67
- 20.08,3.15,Male,No,Sat,Dinner,3
68
- 16.45,2.47,Female,No,Sat,Dinner,2
69
- 3.07,1.0,Female,Yes,Sat,Dinner,1
70
- 20.23,2.01,Male,No,Sat,Dinner,2
71
- 15.01,2.09,Male,Yes,Sat,Dinner,2
72
- 12.02,1.97,Male,No,Sat,Dinner,2
73
- 17.07,3.0,Female,No,Sat,Dinner,3
74
- 26.86,3.14,Female,Yes,Sat,Dinner,2
75
- 25.28,5.0,Female,Yes,Sat,Dinner,2
76
- 14.73,2.2,Female,No,Sat,Dinner,2
77
- 10.51,1.25,Male,No,Sat,Dinner,2
78
- 17.92,3.08,Male,Yes,Sat,Dinner,2
79
- 27.2,4.0,Male,No,Thur,Lunch,4
80
- 22.76,3.0,Male,No,Thur,Lunch,2
81
- 17.29,2.71,Male,No,Thur,Lunch,2
82
- 19.44,3.0,Male,Yes,Thur,Lunch,2
83
- 16.66,3.4,Male,No,Thur,Lunch,2
84
- 10.07,1.83,Female,No,Thur,Lunch,1
85
- 32.68,5.0,Male,Yes,Thur,Lunch,2
86
- 15.98,2.03,Male,No,Thur,Lunch,2
87
- 34.83,5.17,Female,No,Thur,Lunch,4
88
- 13.03,2.0,Male,No,Thur,Lunch,2
89
- 18.28,4.0,Male,No,Thur,Lunch,2
90
- 24.71,5.85,Male,No,Thur,Lunch,2
91
- 21.16,3.0,Male,No,Thur,Lunch,2
92
- 28.97,3.0,Male,Yes,Fri,Dinner,2
93
- 22.49,3.5,Male,No,Fri,Dinner,2
94
- 5.75,1.0,Female,Yes,Fri,Dinner,2
95
- 16.32,4.3,Female,Yes,Fri,Dinner,2
96
- 22.75,3.25,Female,No,Fri,Dinner,2
97
- 40.17,4.73,Male,Yes,Fri,Dinner,4
98
- 27.28,4.0,Male,Yes,Fri,Dinner,2
99
- 12.03,1.5,Male,Yes,Fri,Dinner,2
100
- 21.01,3.0,Male,Yes,Fri,Dinner,2
101
- 12.46,1.5,Male,No,Fri,Dinner,2
102
- 11.35,2.5,Female,Yes,Fri,Dinner,2
103
- 15.38,3.0,Female,Yes,Fri,Dinner,2
104
- 44.3,2.5,Female,Yes,Sat,Dinner,3
105
- 22.42,3.48,Female,Yes,Sat,Dinner,2
106
- 20.92,4.08,Female,No,Sat,Dinner,2
107
- 15.36,1.64,Male,Yes,Sat,Dinner,2
108
- 20.49,4.06,Male,Yes,Sat,Dinner,2
109
- 25.21,4.29,Male,Yes,Sat,Dinner,2
110
- 18.24,3.76,Male,No,Sat,Dinner,2
111
- 14.31,4.0,Female,Yes,Sat,Dinner,2
112
- 14.0,3.0,Male,No,Sat,Dinner,2
113
- 7.25,1.0,Female,No,Sat,Dinner,1
114
- 38.07,4.0,Male,No,Sun,Dinner,3
115
- 23.95,2.55,Male,No,Sun,Dinner,2
116
- 25.71,4.0,Female,No,Sun,Dinner,3
117
- 17.31,3.5,Female,No,Sun,Dinner,2
118
- 29.93,5.07,Male,No,Sun,Dinner,4
119
- 10.65,1.5,Female,No,Thur,Lunch,2
120
- 12.43,1.8,Female,No,Thur,Lunch,2
121
- 24.08,2.92,Female,No,Thur,Lunch,4
122
- 11.69,2.31,Male,No,Thur,Lunch,2
123
- 13.42,1.68,Female,No,Thur,Lunch,2
124
- 14.26,2.5,Male,No,Thur,Lunch,2
125
- 15.95,2.0,Male,No,Thur,Lunch,2
126
- 12.48,2.52,Female,No,Thur,Lunch,2
127
- 29.8,4.2,Female,No,Thur,Lunch,6
128
- 8.52,1.48,Male,No,Thur,Lunch,2
129
- 14.52,2.0,Female,No,Thur,Lunch,2
130
- 11.38,2.0,Female,No,Thur,Lunch,2
131
- 22.82,2.18,Male,No,Thur,Lunch,3
132
- 19.08,1.5,Male,No,Thur,Lunch,2
133
- 20.27,2.83,Female,No,Thur,Lunch,2
134
- 11.17,1.5,Female,No,Thur,Lunch,2
135
- 12.26,2.0,Female,No,Thur,Lunch,2
136
- 18.26,3.25,Female,No,Thur,Lunch,2
137
- 8.51,1.25,Female,No,Thur,Lunch,2
138
- 10.33,2.0,Female,No,Thur,Lunch,2
139
- 14.15,2.0,Female,No,Thur,Lunch,2
140
- 16.0,2.0,Male,Yes,Thur,Lunch,2
141
- 13.16,2.75,Female,No,Thur,Lunch,2
142
- 17.47,3.5,Female,No,Thur,Lunch,2
143
- 34.3,6.7,Male,No,Thur,Lunch,6
144
- 41.19,5.0,Male,No,Thur,Lunch,5
145
- 27.05,5.0,Female,No,Thur,Lunch,6
146
- 16.43,2.3,Female,No,Thur,Lunch,2
147
- 8.35,1.5,Female,No,Thur,Lunch,2
148
- 18.64,1.36,Female,No,Thur,Lunch,3
149
- 11.87,1.63,Female,No,Thur,Lunch,2
150
- 9.78,1.73,Male,No,Thur,Lunch,2
151
- 7.51,2.0,Male,No,Thur,Lunch,2
152
- 14.07,2.5,Male,No,Sun,Dinner,2
153
- 13.13,2.0,Male,No,Sun,Dinner,2
154
- 17.26,2.74,Male,No,Sun,Dinner,3
155
- 24.55,2.0,Male,No,Sun,Dinner,4
156
- 19.77,2.0,Male,No,Sun,Dinner,4
157
- 29.85,5.14,Female,No,Sun,Dinner,5
158
- 48.17,5.0,Male,No,Sun,Dinner,6
159
- 25.0,3.75,Female,No,Sun,Dinner,4
160
- 13.39,2.61,Female,No,Sun,Dinner,2
161
- 16.49,2.0,Male,No,Sun,Dinner,4
162
- 21.5,3.5,Male,No,Sun,Dinner,4
163
- 12.66,2.5,Male,No,Sun,Dinner,2
164
- 16.21,2.0,Female,No,Sun,Dinner,3
165
- 13.81,2.0,Male,No,Sun,Dinner,2
166
- 17.51,3.0,Female,Yes,Sun,Dinner,2
167
- 24.52,3.48,Male,No,Sun,Dinner,3
168
- 20.76,2.24,Male,No,Sun,Dinner,2
169
- 31.71,4.5,Male,No,Sun,Dinner,4
170
- 10.59,1.61,Female,Yes,Sat,Dinner,2
171
- 10.63,2.0,Female,Yes,Sat,Dinner,2
172
- 50.81,10.0,Male,Yes,Sat,Dinner,3
173
- 15.81,3.16,Male,Yes,Sat,Dinner,2
174
- 7.25,5.15,Male,Yes,Sun,Dinner,2
175
- 31.85,3.18,Male,Yes,Sun,Dinner,2
176
- 16.82,4.0,Male,Yes,Sun,Dinner,2
177
- 32.9,3.11,Male,Yes,Sun,Dinner,2
178
- 17.89,2.0,Male,Yes,Sun,Dinner,2
179
- 14.48,2.0,Male,Yes,Sun,Dinner,2
180
- 9.6,4.0,Female,Yes,Sun,Dinner,2
181
- 34.63,3.55,Male,Yes,Sun,Dinner,2
182
- 34.65,3.68,Male,Yes,Sun,Dinner,4
183
- 23.33,5.65,Male,Yes,Sun,Dinner,2
184
- 45.35,3.5,Male,Yes,Sun,Dinner,3
185
- 23.17,6.5,Male,Yes,Sun,Dinner,4
186
- 40.55,3.0,Male,Yes,Sun,Dinner,2
187
- 20.69,5.0,Male,No,Sun,Dinner,5
188
- 20.9,3.5,Female,Yes,Sun,Dinner,3
189
- 30.46,2.0,Male,Yes,Sun,Dinner,5
190
- 18.15,3.5,Female,Yes,Sun,Dinner,3
191
- 23.1,4.0,Male,Yes,Sun,Dinner,3
192
- 15.69,1.5,Male,Yes,Sun,Dinner,2
193
- 19.81,4.19,Female,Yes,Thur,Lunch,2
194
- 28.44,2.56,Male,Yes,Thur,Lunch,2
195
- 15.48,2.02,Male,Yes,Thur,Lunch,2
196
- 16.58,4.0,Male,Yes,Thur,Lunch,2
197
- 7.56,1.44,Male,No,Thur,Lunch,2
198
- 10.34,2.0,Male,Yes,Thur,Lunch,2
199
- 43.11,5.0,Female,Yes,Thur,Lunch,4
200
- 13.0,2.0,Female,Yes,Thur,Lunch,2
201
- 13.51,2.0,Male,Yes,Thur,Lunch,2
202
- 18.71,4.0,Male,Yes,Thur,Lunch,3
203
- 12.74,2.01,Female,Yes,Thur,Lunch,2
204
- 13.0,2.0,Female,Yes,Thur,Lunch,2
205
- 16.4,2.5,Female,Yes,Thur,Lunch,2
206
- 20.53,4.0,Male,Yes,Thur,Lunch,4
207
- 16.47,3.23,Female,Yes,Thur,Lunch,3
208
- 26.59,3.41,Male,Yes,Sat,Dinner,3
209
- 38.73,3.0,Male,Yes,Sat,Dinner,4
210
- 24.27,2.03,Male,Yes,Sat,Dinner,2
211
- 12.76,2.23,Female,Yes,Sat,Dinner,2
212
- 30.06,2.0,Male,Yes,Sat,Dinner,3
213
- 25.89,5.16,Male,Yes,Sat,Dinner,4
214
- 48.33,9.0,Male,No,Sat,Dinner,4
215
- 13.27,2.5,Female,Yes,Sat,Dinner,2
216
- 28.17,6.5,Female,Yes,Sat,Dinner,3
217
- 12.9,1.1,Female,Yes,Sat,Dinner,2
218
- 28.15,3.0,Male,Yes,Sat,Dinner,5
219
- 11.59,1.5,Male,Yes,Sat,Dinner,2
220
- 7.74,1.44,Male,Yes,Sat,Dinner,2
221
- 30.14,3.09,Female,Yes,Sat,Dinner,4
222
- 12.16,2.2,Male,Yes,Fri,Lunch,2
223
- 13.42,3.48,Female,Yes,Fri,Lunch,2
224
- 8.58,1.92,Male,Yes,Fri,Lunch,1
225
- 15.98,3.0,Female,No,Fri,Lunch,3
226
- 13.42,1.58,Male,Yes,Fri,Lunch,2
227
- 16.27,2.5,Female,Yes,Fri,Lunch,2
228
- 10.09,2.0,Female,Yes,Fri,Lunch,2
229
- 20.45,3.0,Male,No,Sat,Dinner,4
230
- 13.28,2.72,Male,No,Sat,Dinner,2
231
- 22.12,2.88,Female,Yes,Sat,Dinner,2
232
- 24.01,2.0,Male,Yes,Sat,Dinner,4
233
- 15.69,3.0,Male,Yes,Sat,Dinner,3
234
- 11.61,3.39,Male,No,Sat,Dinner,2
235
- 10.77,1.47,Male,No,Sat,Dinner,2
236
- 15.53,3.0,Male,Yes,Sat,Dinner,2
237
- 10.07,1.25,Male,No,Sat,Dinner,2
238
- 12.6,1.0,Male,Yes,Sat,Dinner,2
239
- 32.83,1.17,Male,Yes,Sat,Dinner,2
240
- 35.83,4.67,Female,No,Sat,Dinner,3
241
- 29.03,5.92,Male,No,Sat,Dinner,3
242
- 27.18,2.0,Female,Yes,Sat,Dinner,2
243
- 22.67,2.0,Male,Yes,Sat,Dinner,2
244
- 17.82,1.75,Male,No,Sat,Dinner,2
245
- 18.78,3.0,Female,No,Thur,Dinner,2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
usage.md DELETED
@@ -1,3 +0,0 @@
1
- **Quick start**
2
- * Step 1: Go to the Dataset tab to either draw a 2D dataset, upload a local dataset, or chooose a sklearn dataset.
3
- * Step 2: Go to the Classifier tab to select a classifier, then presse the `Train Model` button. The decision boundary will then be generated.