gradio-ci commited on
Commit
7f46969
·
verified ·
1 Parent(s): 529dce7

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