gradio-ci commited on
Commit
bee23c7
·
verified ·
1 Parent(s): a7e056e

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