abidlabs HF Staff commited on
Commit
1a7337f
·
verified ·
1 Parent(s): 620c485

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +1 -0
  2. __init__.py +284 -0
  3. __pycache__/__init__.cpython-310.pyc +0 -0
  4. __pycache__/__init__.cpython-311.pyc +0 -0
  5. __pycache__/__init__.cpython-312.pyc +0 -0
  6. __pycache__/api.cpython-312.pyc +0 -0
  7. __pycache__/cli.cpython-311.pyc +0 -0
  8. __pycache__/cli.cpython-312.pyc +0 -0
  9. __pycache__/commit_scheduler.cpython-311.pyc +0 -0
  10. __pycache__/commit_scheduler.cpython-312.pyc +0 -0
  11. __pycache__/context.cpython-312.pyc +0 -0
  12. __pycache__/context_vars.cpython-311.pyc +0 -0
  13. __pycache__/context_vars.cpython-312.pyc +0 -0
  14. __pycache__/deploy.cpython-310.pyc +0 -0
  15. __pycache__/deploy.cpython-311.pyc +0 -0
  16. __pycache__/deploy.cpython-312.pyc +0 -0
  17. __pycache__/dummy_commit_scheduler.cpython-310.pyc +0 -0
  18. __pycache__/dummy_commit_scheduler.cpython-311.pyc +0 -0
  19. __pycache__/dummy_commit_scheduler.cpython-312.pyc +0 -0
  20. __pycache__/file_storage.cpython-311.pyc +0 -0
  21. __pycache__/file_storage.cpython-312.pyc +0 -0
  22. __pycache__/imports.cpython-311.pyc +0 -0
  23. __pycache__/imports.cpython-312.pyc +0 -0
  24. __pycache__/media.cpython-311.pyc +0 -0
  25. __pycache__/media.cpython-312.pyc +0 -0
  26. __pycache__/run.cpython-310.pyc +0 -0
  27. __pycache__/run.cpython-311.pyc +0 -0
  28. __pycache__/run.cpython-312.pyc +0 -0
  29. __pycache__/sqlite_storage.cpython-310.pyc +0 -0
  30. __pycache__/sqlite_storage.cpython-311.pyc +0 -0
  31. __pycache__/sqlite_storage.cpython-312.pyc +0 -0
  32. __pycache__/storage.cpython-312.pyc +0 -0
  33. __pycache__/table.cpython-311.pyc +0 -0
  34. __pycache__/table.cpython-312.pyc +0 -0
  35. __pycache__/typehints.cpython-311.pyc +0 -0
  36. __pycache__/typehints.cpython-312.pyc +0 -0
  37. __pycache__/types.cpython-312.pyc +0 -0
  38. __pycache__/ui.cpython-310.pyc +0 -0
  39. __pycache__/ui.cpython-311.pyc +0 -0
  40. __pycache__/ui.cpython-312.pyc +0 -0
  41. __pycache__/utils.cpython-310.pyc +0 -0
  42. __pycache__/utils.cpython-311.pyc +0 -0
  43. __pycache__/utils.cpython-312.pyc +0 -0
  44. __pycache__/video_writer.cpython-311.pyc +0 -0
  45. __pycache__/video_writer.cpython-312.pyc +0 -0
  46. assets/trackio_logo_dark.png +0 -0
  47. assets/trackio_logo_light.png +0 -0
  48. assets/trackio_logo_old.png +3 -0
  49. assets/trackio_logo_type_dark.png +0 -0
  50. assets/trackio_logo_type_dark_transparent.png +0 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ assets/trackio_logo_old.png filter=lfs diff=lfs merge=lfs -text
__init__.py ADDED
@@ -0,0 +1,284 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import hashlib
2
+ import os
3
+ import secrets
4
+ import warnings
5
+ import webbrowser
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from gradio.blocks import BUILT_IN_THEMES
10
+ from gradio.themes import Default as DefaultTheme
11
+ from gradio.themes import ThemeClass
12
+ from gradio_client import Client
13
+ from huggingface_hub import SpaceStorage
14
+
15
+ from trackio import context_vars, deploy, utils
16
+ from trackio.imports import import_csv, import_tf_events
17
+ from trackio.media import TrackioImage, TrackioVideo
18
+ from trackio.run import Run
19
+ from trackio.sqlite_storage import SQLiteStorage
20
+ from trackio.table import Table
21
+ from trackio.ui.main import demo
22
+ from trackio.ui.runs import run_page
23
+ from trackio.utils import TRACKIO_DIR, TRACKIO_LOGO_DIR
24
+
25
+ __version__ = Path(__file__).parent.joinpath("version.txt").read_text().strip()
26
+
27
+ __all__ = [
28
+ "init",
29
+ "log",
30
+ "finish",
31
+ "show",
32
+ "import_csv",
33
+ "import_tf_events",
34
+ "Image",
35
+ "Video",
36
+ "Table",
37
+ ]
38
+
39
+ Image = TrackioImage
40
+ Video = TrackioVideo
41
+
42
+
43
+ config = {}
44
+
45
+ DEFAULT_THEME = "citrus"
46
+
47
+
48
+ def init(
49
+ project: str,
50
+ name: str | None = None,
51
+ space_id: str | None = None,
52
+ space_storage: SpaceStorage | None = None,
53
+ dataset_id: str | None = None,
54
+ config: dict | None = None,
55
+ resume: str = "never",
56
+ settings: Any = None,
57
+ private: bool | None = None,
58
+ ) -> Run:
59
+ """
60
+ Creates a new Trackio project and returns a [`Run`] object.
61
+
62
+ Args:
63
+ project (`str`):
64
+ The name of the project (can be an existing project to continue tracking or
65
+ a new project to start tracking from scratch).
66
+ name (`str`, *optional*):
67
+ The name of the run (if not provided, a default name will be generated).
68
+ space_id (`str`, *optional*):
69
+ If provided, the project will be logged to a Hugging Face Space instead of
70
+ a local directory. Should be a complete Space name like
71
+ `"username/reponame"` or `"orgname/reponame"`, or just `"reponame"` in which
72
+ case the Space will be created in the currently-logged-in Hugging Face
73
+ user's namespace. If the Space does not exist, it will be created. If the
74
+ Space already exists, the project will be logged to it.
75
+ space_storage ([`~huggingface_hub.SpaceStorage`], *optional*):
76
+ Choice of persistent storage tier.
77
+ dataset_id (`str`, *optional*):
78
+ If a `space_id` is provided, a persistent Hugging Face Dataset will be
79
+ created and the metrics will be synced to it every 5 minutes. Specify a
80
+ Dataset with name like `"username/datasetname"` or `"orgname/datasetname"`,
81
+ or `"datasetname"` (uses currently-logged-in Hugging Face user's namespace),
82
+ or `None` (uses the same name as the Space but with the `"_dataset"`
83
+ suffix). If the Dataset does not exist, it will be created. If the Dataset
84
+ already exists, the project will be appended to it.
85
+ config (`dict`, *optional*):
86
+ A dictionary of configuration options. Provided for compatibility with
87
+ `wandb.init()`.
88
+ resume (`str`, *optional*, defaults to `"never"`):
89
+ Controls how to handle resuming a run. Can be one of:
90
+
91
+ - `"must"`: Must resume the run with the given name, raises error if run
92
+ doesn't exist
93
+ - `"allow"`: Resume the run if it exists, otherwise create a new run
94
+ - `"never"`: Never resume a run, always create a new one
95
+ private (`bool`, *optional*):
96
+ Whether to make the Space private. If None (default), the repo will be
97
+ public unless the organization's default is private. This value is ignored
98
+ if the repo already exists.
99
+ settings (`Any`, *optional*):
100
+ Not used. Provided for compatibility with `wandb.init()`.
101
+
102
+ Returns:
103
+ `Run`: A [`Run`] object that can be used to log metrics and finish the run.
104
+ """
105
+ if settings is not None:
106
+ warnings.warn(
107
+ "* Warning: settings is not used. Provided for compatibility with wandb.init(). Please create an issue at: https://github.com/gradio-app/trackio/issues if you need a specific feature implemented."
108
+ )
109
+
110
+ if space_id is None and dataset_id is not None:
111
+ raise ValueError("Must provide a `space_id` when `dataset_id` is provided.")
112
+ space_id, dataset_id = utils.preprocess_space_and_dataset_ids(space_id, dataset_id)
113
+ url = context_vars.current_server.get()
114
+
115
+ if url is None:
116
+ if space_id is None:
117
+ _, url, _ = demo.launch(
118
+ show_api=False,
119
+ inline=False,
120
+ quiet=True,
121
+ prevent_thread_lock=True,
122
+ show_error=True,
123
+ )
124
+ else:
125
+ url = space_id
126
+ context_vars.current_server.set(url)
127
+
128
+ if (
129
+ context_vars.current_project.get() is None
130
+ or context_vars.current_project.get() != project
131
+ ):
132
+ print(f"* Trackio project initialized: {project}")
133
+
134
+ if dataset_id is not None:
135
+ os.environ["TRACKIO_DATASET_ID"] = dataset_id
136
+ print(
137
+ f"* Trackio metrics will be synced to Hugging Face Dataset: {dataset_id}"
138
+ )
139
+ if space_id is None:
140
+ print(f"* Trackio metrics logged to: {TRACKIO_DIR}")
141
+ utils.print_dashboard_instructions(project)
142
+ else:
143
+ deploy.create_space_if_not_exists(
144
+ space_id, space_storage, dataset_id, private
145
+ )
146
+ print(
147
+ f"* View dashboard by going to: {deploy.SPACE_URL.format(space_id=space_id)}"
148
+ )
149
+ context_vars.current_project.set(project)
150
+
151
+ client = None
152
+ if not space_id:
153
+ client = Client(url, verbose=False)
154
+
155
+ if resume == "must":
156
+ if name is None:
157
+ raise ValueError("Must provide a run name when resume='must'")
158
+ if name not in SQLiteStorage.get_runs(project):
159
+ raise ValueError(f"Run '{name}' does not exist in project '{project}'")
160
+ resumed = True
161
+ elif resume == "allow":
162
+ resumed = name is not None and name in SQLiteStorage.get_runs(project)
163
+ elif resume == "never":
164
+ if name is not None and name in SQLiteStorage.get_runs(project):
165
+ warnings.warn(
166
+ f"* Warning: resume='never' but a run '{name}' already exists in "
167
+ f"project '{project}'. Generating a new name and instead. If you want "
168
+ "to resume this run, call init() with resume='must' or resume='allow'."
169
+ )
170
+ name = None
171
+ resumed = False
172
+ else:
173
+ raise ValueError("resume must be one of: 'must', 'allow', or 'never'")
174
+
175
+ run = Run(
176
+ url=url,
177
+ project=project,
178
+ client=client,
179
+ name=name,
180
+ config=config,
181
+ space_id=space_id,
182
+ )
183
+
184
+ if resumed:
185
+ print(f"* Resumed existing run: {run.name}")
186
+ else:
187
+ print(f"* Created new run: {run.name}")
188
+
189
+ context_vars.current_run.set(run)
190
+ globals()["config"] = run.config
191
+ return run
192
+
193
+
194
+ def log(metrics: dict, step: int | None = None) -> None:
195
+ """
196
+ Logs metrics to the current run.
197
+
198
+ Args:
199
+ metrics (`dict`):
200
+ A dictionary of metrics to log.
201
+ step (`int`, *optional*):
202
+ The step number. If not provided, the step will be incremented
203
+ automatically.
204
+ """
205
+ run = context_vars.current_run.get()
206
+ if run is None:
207
+ raise RuntimeError("Call trackio.init() before trackio.log().")
208
+ run.log(
209
+ metrics=metrics,
210
+ step=step,
211
+ )
212
+
213
+
214
+ def finish():
215
+ """
216
+ Finishes the current run.
217
+ """
218
+ run = context_vars.current_run.get()
219
+ if run is None:
220
+ raise RuntimeError("Call trackio.init() before trackio.finish().")
221
+ run.finish()
222
+
223
+
224
+ def show(project: str | None = None, theme: str | ThemeClass = DEFAULT_THEME):
225
+ """
226
+ Launches the Trackio dashboard.
227
+
228
+ Args:
229
+ project (`str`, *optional*):
230
+ The name of the project whose runs to show. If not provided, all projects
231
+ will be shown and the user can select one.
232
+ theme (`str` or `ThemeClass`, *optional*, defaults to `"citrus"`):
233
+ A Gradio Theme to use for the dashboard instead of the default `"citrus"`,
234
+ can be a built-in theme (e.g. `'soft'`, `'default'`), a theme from the Hub
235
+ (e.g. `"gstaff/xkcd"`), or a custom Theme class.
236
+ """
237
+ write_token = secrets.token_urlsafe(32)
238
+
239
+ demo.write_token = write_token
240
+ run_page.write_token = write_token
241
+
242
+ if theme != DEFAULT_THEME:
243
+ # TODO: It's a little hacky to reproduce this theme-setting logic from Gradio Blocks,
244
+ # but in Gradio 6.0, the theme will be set in `launch()` instead, which means that we
245
+ # will be able to remove this code.
246
+ if isinstance(theme, str):
247
+ if theme.lower() in BUILT_IN_THEMES:
248
+ theme = BUILT_IN_THEMES[theme.lower()]
249
+ else:
250
+ try:
251
+ theme = ThemeClass.from_hub(theme)
252
+ except Exception as e:
253
+ warnings.warn(f"Cannot load {theme}. Caught Exception: {str(e)}")
254
+ theme = DefaultTheme()
255
+ if not isinstance(theme, ThemeClass):
256
+ warnings.warn("Theme should be a class loaded from gradio.themes")
257
+ theme = DefaultTheme()
258
+ demo.theme: ThemeClass = theme
259
+ demo.theme_css = theme._get_theme_css()
260
+ demo.stylesheets = theme._stylesheets
261
+ theme_hasher = hashlib.sha256()
262
+ theme_hasher.update(demo.theme_css.encode("utf-8"))
263
+ demo.theme_hash = theme_hasher.hexdigest()
264
+
265
+ _, url, share_url = demo.launch(
266
+ show_api=False,
267
+ quiet=True,
268
+ inline=utils.is_in_notebook(),
269
+ prevent_thread_lock=True,
270
+ favicon_path=TRACKIO_LOGO_DIR / "trackio_logo_light.png",
271
+ allowed_paths=[TRACKIO_LOGO_DIR],
272
+ )
273
+
274
+ base_url = share_url + "/" if share_url else url
275
+
276
+ params = [f"write_token={write_token}"]
277
+ if project:
278
+ params.append(f"project={project}")
279
+ dashboard_url = base_url + "?" + "&".join(params)
280
+
281
+ if not utils.is_in_notebook():
282
+ print(f"* Trackio UI launched at: {dashboard_url}")
283
+ webbrowser.open(dashboard_url)
284
+ utils.block_except_in_notebook()
__pycache__/__init__.cpython-310.pyc ADDED
Binary file (4.96 kB). View file
 
__pycache__/__init__.cpython-311.pyc ADDED
Binary file (13.2 kB). View file
 
__pycache__/__init__.cpython-312.pyc ADDED
Binary file (12.2 kB). View file
 
__pycache__/api.cpython-312.pyc ADDED
Binary file (4.56 kB). View file
 
__pycache__/cli.cpython-311.pyc ADDED
Binary file (1.57 kB). View file
 
__pycache__/cli.cpython-312.pyc ADDED
Binary file (1.43 kB). View file
 
__pycache__/commit_scheduler.cpython-311.pyc ADDED
Binary file (20.2 kB). View file
 
__pycache__/commit_scheduler.cpython-312.pyc ADDED
Binary file (18.8 kB). View file
 
__pycache__/context.cpython-312.pyc ADDED
Binary file (440 Bytes). View file
 
__pycache__/context_vars.cpython-311.pyc ADDED
Binary file (840 Bytes). View file
 
__pycache__/context_vars.cpython-312.pyc ADDED
Binary file (763 Bytes). View file
 
__pycache__/deploy.cpython-310.pyc ADDED
Binary file (1.72 kB). View file
 
__pycache__/deploy.cpython-311.pyc ADDED
Binary file (9.66 kB). View file
 
__pycache__/deploy.cpython-312.pyc ADDED
Binary file (8.74 kB). View file
 
__pycache__/dummy_commit_scheduler.cpython-310.pyc ADDED
Binary file (936 Bytes). View file
 
__pycache__/dummy_commit_scheduler.cpython-311.pyc ADDED
Binary file (1.19 kB). View file
 
__pycache__/dummy_commit_scheduler.cpython-312.pyc ADDED
Binary file (1.01 kB). View file
 
__pycache__/file_storage.cpython-311.pyc ADDED
Binary file (1.88 kB). View file
 
__pycache__/file_storage.cpython-312.pyc ADDED
Binary file (1.63 kB). View file
 
__pycache__/imports.cpython-311.pyc ADDED
Binary file (14.3 kB). View file
 
__pycache__/imports.cpython-312.pyc ADDED
Binary file (13.2 kB). View file
 
__pycache__/media.cpython-311.pyc ADDED
Binary file (15.1 kB). View file
 
__pycache__/media.cpython-312.pyc ADDED
Binary file (14.1 kB). View file
 
__pycache__/run.cpython-310.pyc ADDED
Binary file (1.01 kB). View file
 
__pycache__/run.cpython-311.pyc ADDED
Binary file (9.59 kB). View file
 
__pycache__/run.cpython-312.pyc ADDED
Binary file (8.7 kB). View file
 
__pycache__/sqlite_storage.cpython-310.pyc ADDED
Binary file (5.37 kB). View file
 
__pycache__/sqlite_storage.cpython-311.pyc ADDED
Binary file (32.8 kB). View file
 
__pycache__/sqlite_storage.cpython-312.pyc ADDED
Binary file (27.5 kB). View file
 
__pycache__/storage.cpython-312.pyc ADDED
Binary file (4.6 kB). View file
 
__pycache__/table.cpython-311.pyc ADDED
Binary file (2.52 kB). View file
 
__pycache__/table.cpython-312.pyc ADDED
Binary file (2.33 kB). View file
 
__pycache__/typehints.cpython-311.pyc ADDED
Binary file (1.12 kB). View file
 
__pycache__/typehints.cpython-312.pyc ADDED
Binary file (908 Bytes). View file
 
__pycache__/types.cpython-312.pyc ADDED
Binary file (531 Bytes). View file
 
__pycache__/ui.cpython-310.pyc ADDED
Binary file (7.83 kB). View file
 
__pycache__/ui.cpython-311.pyc ADDED
Binary file (38.1 kB). View file
 
__pycache__/ui.cpython-312.pyc ADDED
Binary file (33 kB). View file
 
__pycache__/utils.cpython-310.pyc ADDED
Binary file (2.62 kB). View file
 
__pycache__/utils.cpython-311.pyc ADDED
Binary file (23.6 kB). View file
 
__pycache__/utils.cpython-312.pyc ADDED
Binary file (21.3 kB). View file
 
__pycache__/video_writer.cpython-311.pyc ADDED
Binary file (5.72 kB). View file
 
__pycache__/video_writer.cpython-312.pyc ADDED
Binary file (5.33 kB). View file
 
assets/trackio_logo_dark.png ADDED
assets/trackio_logo_light.png ADDED
assets/trackio_logo_old.png ADDED

Git LFS Details

  • SHA256: 3922c4d1e465270ad4d8abb12023f3beed5d9f7f338528a4c0ac21dcf358a1c8
  • Pointer size: 131 Bytes
  • Size of remote file: 487 kB
assets/trackio_logo_type_dark.png ADDED
assets/trackio_logo_type_dark_transparent.png ADDED