abidlabs HF Staff commited on
Commit
526e1ea
·
verified ·
1 Parent(s): 2d0979a

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 +264 -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,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 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
+ ) -> Run:
56
+ """
57
+ Creates a new Trackio project and returns a [`Run`] object.
58
+
59
+ Args:
60
+ project (`str`):
61
+ The name of the project (can be an existing project to continue tracking or
62
+ a new project to start tracking from scratch).
63
+ name (`str` or `None`, *optional*, defaults to `None`):
64
+ The name of the run (if not provided, a default name will be generated).
65
+ space_id (`str` or `None`, *optional*, defaults to `None`):
66
+ If provided, the project will be logged to a Hugging Face Space instead of
67
+ a local directory. Should be a complete Space name like
68
+ `"username/reponame"` or `"orgname/reponame"`, or just `"reponame"` in which
69
+ case the Space will be created in the currently-logged-in Hugging Face
70
+ user's namespace. If the Space does not exist, it will be created. If the
71
+ Space already exists, the project will be logged to it.
72
+ space_storage ([`~huggingface_hub.SpaceStorage`] or `None`, *optional*, defaults to `None`):
73
+ Choice of persistent storage tier.
74
+ dataset_id (`str` or `None`, *optional*, defaults to `None`):
75
+ If a `space_id` is provided, a persistent Hugging Face Dataset will be
76
+ created and the metrics will be synced to it every 5 minutes. Specify a
77
+ Dataset with name like `"username/datasetname"` or `"orgname/datasetname"`,
78
+ or `"datasetname"` (uses currently-logged-in Hugging Face user's namespace),
79
+ or `None` (uses the same name as the Space but with the `"_dataset"`
80
+ suffix). If the Dataset does not exist, it will be created. If the Dataset
81
+ already exists, the project will be appended to it.
82
+ config (`dict` or `None`, *optional*, defaults to `None`):
83
+ A dictionary of configuration options. Provided for compatibility with
84
+ `wandb.init()`.
85
+ resume (`str`, *optional*, defaults to `"never"`):
86
+ Controls how to handle resuming a run. Can be one of:
87
+
88
+ - `"must"`: Must resume the run with the given name, raises error if run
89
+ doesn't exist
90
+ - `"allow"`: Resume the run if it exists, otherwise create a new run
91
+ - `"never"`: Never resume a run, always create a new one
92
+ settings (`Any`, *optional*, defaults to `None`):
93
+ Not used. Provided for compatibility with `wandb.init()`.
94
+
95
+ Returns:
96
+ `Run`: A [`Run`] object that can be used to log metrics and finish the run.
97
+ """
98
+ if settings is not None:
99
+ warnings.warn(
100
+ "* 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."
101
+ )
102
+
103
+ if space_id is None and dataset_id is not None:
104
+ raise ValueError("Must provide a `space_id` when `dataset_id` is provided.")
105
+ space_id, dataset_id = utils.preprocess_space_and_dataset_ids(space_id, dataset_id)
106
+ url = context_vars.current_server.get()
107
+
108
+ if url is None:
109
+ if space_id is None:
110
+ _, url, _ = demo.launch(
111
+ show_api=False,
112
+ inline=False,
113
+ quiet=True,
114
+ prevent_thread_lock=True,
115
+ show_error=True,
116
+ )
117
+ else:
118
+ url = space_id
119
+ context_vars.current_server.set(url)
120
+
121
+ if (
122
+ context_vars.current_project.get() is None
123
+ or context_vars.current_project.get() != project
124
+ ):
125
+ print(f"* Trackio project initialized: {project}")
126
+
127
+ if dataset_id is not None:
128
+ os.environ["TRACKIO_DATASET_ID"] = dataset_id
129
+ print(
130
+ f"* Trackio metrics will be synced to Hugging Face Dataset: {dataset_id}"
131
+ )
132
+ if space_id is None:
133
+ print(f"* Trackio metrics logged to: {TRACKIO_DIR}")
134
+ utils.print_dashboard_instructions(project)
135
+ else:
136
+ deploy.create_space_if_not_exists(space_id, space_storage, dataset_id)
137
+ print(
138
+ f"* View dashboard by going to: {deploy.SPACE_URL.format(space_id=space_id)}"
139
+ )
140
+ context_vars.current_project.set(project)
141
+
142
+ client = None
143
+ if not space_id:
144
+ client = Client(url, verbose=False)
145
+
146
+ if resume == "must":
147
+ if name is None:
148
+ raise ValueError("Must provide a run name when resume='must'")
149
+ if name not in SQLiteStorage.get_runs(project):
150
+ raise ValueError(f"Run '{name}' does not exist in project '{project}'")
151
+ resumed = True
152
+ elif resume == "allow":
153
+ resumed = name is not None and name in SQLiteStorage.get_runs(project)
154
+ elif resume == "never":
155
+ if name is not None and name in SQLiteStorage.get_runs(project):
156
+ warnings.warn(
157
+ f"* Warning: resume='never' but a run '{name}' already exists in "
158
+ f"project '{project}'. Generating a new name and instead. If you want "
159
+ "to resume this run, call init() with resume='must' or resume='allow'."
160
+ )
161
+ name = None
162
+ resumed = False
163
+ else:
164
+ raise ValueError("resume must be one of: 'must', 'allow', or 'never'")
165
+
166
+ run = Run(
167
+ url=url,
168
+ project=project,
169
+ client=client,
170
+ name=name,
171
+ config=config,
172
+ space_id=space_id,
173
+ )
174
+
175
+ if resumed:
176
+ print(f"* Resumed existing run: {run.name}")
177
+ else:
178
+ print(f"* Created new run: {run.name}")
179
+
180
+ context_vars.current_run.set(run)
181
+ globals()["config"] = run.config
182
+ return run
183
+
184
+
185
+ def log(metrics: dict, step: int | None = None) -> None:
186
+ """
187
+ Logs metrics to the current run.
188
+
189
+ Args:
190
+ metrics (`dict`):
191
+ A dictionary of metrics to log.
192
+ step (`int` or `None`, *optional*, defaults to `None`):
193
+ The step number. If not provided, the step will be incremented
194
+ automatically.
195
+ """
196
+ run = context_vars.current_run.get()
197
+ if run is None:
198
+ raise RuntimeError("Call trackio.init() before trackio.log().")
199
+ run.log(
200
+ metrics=metrics,
201
+ step=step,
202
+ )
203
+
204
+
205
+ def finish():
206
+ """
207
+ Finishes the current run.
208
+ """
209
+ run = context_vars.current_run.get()
210
+ if run is None:
211
+ raise RuntimeError("Call trackio.init() before trackio.finish().")
212
+ run.finish()
213
+
214
+
215
+ def show(project: str | None = None, theme: str | ThemeClass = DEFAULT_THEME):
216
+ """
217
+ Launches the Trackio dashboard.
218
+
219
+ Args:
220
+ project (`str` or `None`, *optional*, defaults to `None`):
221
+ The name of the project whose runs to show. If not provided, all projects
222
+ will be shown and the user can select one.
223
+ theme (`str` or `ThemeClass`, *optional*, defaults to `"citrus"`):
224
+ A Gradio Theme to use for the dashboard instead of the default `"citrus"`,
225
+ can be a built-in theme (e.g. `'soft'`, `'default'`), a theme from the Hub
226
+ (e.g. `"gstaff/xkcd"`), or a custom Theme class.
227
+ """
228
+ if theme != DEFAULT_THEME:
229
+ # TODO: It's a little hacky to reproduce this theme-setting logic from Gradio Blocks,
230
+ # but in Gradio 6.0, the theme will be set in `launch()` instead, which means that we
231
+ # will be able to remove this code.
232
+ if isinstance(theme, str):
233
+ if theme.lower() in BUILT_IN_THEMES:
234
+ theme = BUILT_IN_THEMES[theme.lower()]
235
+ else:
236
+ try:
237
+ theme = ThemeClass.from_hub(theme)
238
+ except Exception as e:
239
+ warnings.warn(f"Cannot load {theme}. Caught Exception: {str(e)}")
240
+ theme = DefaultTheme()
241
+ if not isinstance(theme, ThemeClass):
242
+ warnings.warn("Theme should be a class loaded from gradio.themes")
243
+ theme = DefaultTheme()
244
+ demo.theme: ThemeClass = theme
245
+ demo.theme_css = theme._get_theme_css()
246
+ demo.stylesheets = theme._stylesheets
247
+ theme_hasher = hashlib.sha256()
248
+ theme_hasher.update(demo.theme_css.encode("utf-8"))
249
+ demo.theme_hash = theme_hasher.hexdigest()
250
+
251
+ _, url, share_url = demo.launch(
252
+ show_api=False,
253
+ quiet=True,
254
+ inline=False,
255
+ prevent_thread_lock=True,
256
+ favicon_path=TRACKIO_LOGO_DIR / "trackio_logo_light.png",
257
+ allowed_paths=[TRACKIO_LOGO_DIR],
258
+ )
259
+
260
+ base_url = share_url + "/" if share_url else url
261
+ dashboard_url = base_url + f"?project={project}" if project else base_url
262
+ print(f"* Trackio UI launched at: {dashboard_url}")
263
+ webbrowser.open(dashboard_url)
264
+ 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 (12.5 kB). View file
 
__pycache__/__init__.cpython-312.pyc ADDED
Binary file (11.6 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.4 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.33 kB). View file
 
__pycache__/deploy.cpython-312.pyc ADDED
Binary file (8.42 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 (3.14 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 (13.8 kB). View file
 
__pycache__/imports.cpython-312.pyc ADDED
Binary file (12.8 kB). View file
 
__pycache__/media.cpython-311.pyc ADDED
Binary file (6.39 kB). View file
 
__pycache__/media.cpython-312.pyc ADDED
Binary file (14.2 kB). View file
 
__pycache__/run.cpython-310.pyc ADDED
Binary file (1.01 kB). View file
 
__pycache__/run.cpython-311.pyc ADDED
Binary file (8.28 kB). View file
 
__pycache__/run.cpython-312.pyc ADDED
Binary file (7.49 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 (26 kB). View file
 
__pycache__/sqlite_storage.cpython-312.pyc ADDED
Binary file (21.6 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.7 kB). View file
 
__pycache__/table.cpython-312.pyc ADDED
Binary file (2.47 kB). View file
 
__pycache__/typehints.cpython-311.pyc ADDED
Binary file (1.06 kB). View file
 
__pycache__/typehints.cpython-312.pyc ADDED
Binary file (855 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 (37.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 (21.5 kB). View file
 
__pycache__/utils.cpython-312.pyc ADDED
Binary file (19.5 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