abidlabs HF Staff commited on
Commit
518b1fc
·
verified ·
1 Parent(s): 5d605b8

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