hysts HF staff commited on
Commit
bd420fb
1 Parent(s): 400839c
Files changed (3) hide show
  1. app.py +3 -2
  2. app_training.py +6 -3
  3. trainer.py +0 -6
app.py CHANGED
@@ -24,6 +24,7 @@ SHARED_UI_WARNING = f'''## Attention - Training doesn't work in this shared UI.
24
  <center><a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="margin-top:0;margin-bottom:0" src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></center>
25
  '''
26
 
 
27
  if os.getenv('SYSTEM') == 'spaces' and SPACE_ID != ORIGINAL_SPACE_ID:
28
  SETTINGS = f'<a href="https://huggingface.co/spaces/{SPACE_ID}/settings">Settings</a>'
29
  else:
@@ -57,7 +58,7 @@ pipe = InferencePipeline(HF_TOKEN)
57
  trainer = Trainer(HF_TOKEN)
58
 
59
  with gr.Blocks(css='style.css') as demo:
60
- if SPACE_ID == ORIGINAL_SPACE_ID:
61
  show_warning(SHARED_UI_WARNING)
62
  elif not torch.cuda.is_available():
63
  show_warning(CUDA_NOT_AVAILABLE_WARNING)
@@ -67,7 +68,7 @@ with gr.Blocks(css='style.css') as demo:
67
  gr.Markdown(TITLE)
68
  with gr.Tabs():
69
  with gr.TabItem('Train'):
70
- create_training_demo(trainer, pipe)
71
  with gr.TabItem('Run'):
72
  create_inference_demo(pipe, HF_TOKEN)
73
  with gr.TabItem('Upload'):
 
24
  <center><a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img style="margin-top:0;margin-bottom:0" src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></center>
25
  '''
26
 
27
+ IS_SHARED_UI = SPACE_ID == ORIGINAL_SPACE_ID
28
  if os.getenv('SYSTEM') == 'spaces' and SPACE_ID != ORIGINAL_SPACE_ID:
29
  SETTINGS = f'<a href="https://huggingface.co/spaces/{SPACE_ID}/settings">Settings</a>'
30
  else:
 
58
  trainer = Trainer(HF_TOKEN)
59
 
60
  with gr.Blocks(css='style.css') as demo:
61
+ if IS_SHARED_UI:
62
  show_warning(SHARED_UI_WARNING)
63
  elif not torch.cuda.is_available():
64
  show_warning(CUDA_NOT_AVAILABLE_WARNING)
 
68
  gr.Markdown(TITLE)
69
  with gr.Tabs():
70
  with gr.TabItem('Train'):
71
+ create_training_demo(trainer, pipe, disable_training=IS_SHARED_UI)
72
  with gr.TabItem('Run'):
73
  create_inference_demo(pipe, HF_TOKEN)
74
  with gr.TabItem('Upload'):
app_training.py CHANGED
@@ -13,7 +13,8 @@ from trainer import Trainer
13
 
14
 
15
  def create_training_demo(trainer: Trainer,
16
- pipe: InferencePipeline | None = None) -> gr.Blocks:
 
17
  def read_log() -> str:
18
  with open(trainer.log_file) as f:
19
  lines = f.readlines()
@@ -111,7 +112,8 @@ def create_training_demo(trainer: Trainer,
111
  value=False,
112
  interactive=bool(os.getenv('SPACE_ID')),
113
  visible=False)
114
- run_button = gr.Button('Start Training')
 
115
 
116
  with gr.Box():
117
  gr.Text(label='Log',
@@ -119,7 +121,8 @@ def create_training_demo(trainer: Trainer,
119
  lines=10,
120
  max_lines=10,
121
  every=1)
122
- if not os.getenv('DISABLE_SYSTEM_MONITOR'):
 
123
  with gr.Accordion(label='System info', open=False):
124
  create_monitor_demo()
125
 
 
13
 
14
 
15
  def create_training_demo(trainer: Trainer,
16
+ pipe: InferencePipeline | None = None,
17
+ disable_training: bool = False) -> gr.Blocks:
18
  def read_log() -> str:
19
  with open(trainer.log_file) as f:
20
  lines = f.readlines()
 
112
  value=False,
113
  interactive=bool(os.getenv('SPACE_ID')),
114
  visible=False)
115
+ run_button = gr.Button('Start Training',
116
+ interactive=not disable_training)
117
 
118
  with gr.Box():
119
  gr.Text(label='Log',
 
121
  lines=10,
122
  max_lines=10,
123
  every=1)
124
+ if not disable_training and not os.getenv(
125
+ 'DISABLE_SYSTEM_MONITOR'):
126
  with gr.Accordion(label='System info', open=False):
127
  create_monitor_demo()
128
 
trainer.py CHANGED
@@ -20,8 +20,6 @@ from utils import save_model_card
20
  sys.path.append('Tune-A-Video')
21
 
22
  URL_TO_JOIN_MODEL_LIBRARY_ORG = 'https://huggingface.co/organizations/Tune-A-Video-library/share/YjTcaNJmKyeHFpMBioHhzBcTzCYddVErEk'
23
- ORIGINAL_SPACE_ID = 'Tune-A-Video-library/Tune-A-Video-Training-UI'
24
- SPACE_ID = os.getenv('SPACE_ID')
25
 
26
 
27
  class Trainer:
@@ -76,10 +74,6 @@ class Trainer:
76
  remove_gpu_after_training: bool,
77
  input_token: str,
78
  ) -> None:
79
- if SPACE_ID == ORIGINAL_SPACE_ID:
80
- raise gr.Error(
81
- 'This Space does not work on this Shared UI. Duplicate the Space and attribute a GPU'
82
- )
83
  if not torch.cuda.is_available():
84
  raise gr.Error('CUDA is not available.')
85
  if training_video is None:
 
20
  sys.path.append('Tune-A-Video')
21
 
22
  URL_TO_JOIN_MODEL_LIBRARY_ORG = 'https://huggingface.co/organizations/Tune-A-Video-library/share/YjTcaNJmKyeHFpMBioHhzBcTzCYddVErEk'
 
 
23
 
24
 
25
  class Trainer:
 
74
  remove_gpu_after_training: bool,
75
  input_token: str,
76
  ) -> None:
 
 
 
 
77
  if not torch.cuda.is_available():
78
  raise gr.Error('CUDA is not available.')
79
  if training_video is None: