multimodalart HF staff commited on
Commit
b824bb4
Β·
1 Parent(s): 4d01f09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -11,6 +11,8 @@ import pathlib
11
  import shlex
12
  import subprocess
13
 
 
 
14
  if os.getenv('SYSTEM') == 'spaces':
15
  with open('patch') as f:
16
  subprocess.run(shlex.split('patch -p1'), stdin=f, cwd='ControlNet')
@@ -34,10 +36,13 @@ for name in names:
34
  continue
35
  subprocess.run(shlex.split(command), cwd='ControlNet/annotator/ckpts/')
36
 
37
- from model import (DEFAULT_BASE_MODEL_FILENAME, DEFAULT_BASE_MODEL_REPO,
38
- DEFAULT_BASE_MODEL_URL, Model)
39
 
40
- model = Model()
 
 
 
 
 
41
 
42
 
43
  def controlnet(i, prompt, control_task, seed_in, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold):
@@ -155,6 +160,8 @@ def create_video(frames, fps, type):
155
 
156
 
157
  def infer(prompt,video_in, control_task, seed_in, trim_value, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold, gif_import):
 
 
158
  print(f"""
159
  β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
160
  {prompt}
@@ -248,6 +255,14 @@ article = """
248
  """
249
 
250
  with gr.Blocks(css='style.css') as demo:
 
 
 
 
 
 
 
 
251
  with gr.Column(elem_id="col-container"):
252
  gr.HTML(title)
253
  gr.HTML("""
@@ -301,30 +316,30 @@ with gr.Blocks(css='style.css') as demo:
301
 
302
  with gr.Tab("Custom Model"):
303
  current_base_model = gr.Text(label='Current base model',
304
- value=DEFAULT_BASE_MODEL_URL)
305
  with gr.Row():
306
  with gr.Column():
307
  base_model_repo = gr.Text(label='Base model repo',
308
  max_lines=1,
309
- placeholder=DEFAULT_BASE_MODEL_REPO,
310
  interactive=True)
311
  base_model_filename = gr.Text(
312
  label='Base model file',
313
  max_lines=1,
314
- placeholder=DEFAULT_BASE_MODEL_FILENAME,
315
  interactive=True)
316
  change_base_model_button = gr.Button('Change base model')
317
 
318
  gr.HTML(
319
  '''<p>You can use other base models by specifying the repository name and filename.<br />
320
  The base model must be compatible with Stable Diffusion v1.5.</p>''')
321
-
322
- change_base_model_button.click(fn=model.set_base_model,
323
- inputs=[
324
- base_model_repo,
325
- base_model_filename,
326
- ],
327
- outputs=current_base_model, queue=False)
328
 
329
  submit_btn = gr.Button("Generate ControlNet video")
330
 
 
11
  import shlex
12
  import subprocess
13
 
14
+ is_shared_ui = True if "AIFILMS/ControlNet-Video" in os.environ['SPACE_ID'] else False
15
+
16
  if os.getenv('SYSTEM') == 'spaces':
17
  with open('patch') as f:
18
  subprocess.run(shlex.split('patch -p1'), stdin=f, cwd='ControlNet')
 
36
  continue
37
  subprocess.run(shlex.split(command), cwd='ControlNet/annotator/ckpts/')
38
 
 
 
39
 
40
+
41
+ if(not is_shared_ui):
42
+ from model import (DEFAULT_BASE_MODEL_FILENAME, DEFAULT_BASE_MODEL_REPO,
43
+ DEFAULT_BASE_MODEL_URL, Model)
44
+
45
+ model = Model()
46
 
47
 
48
  def controlnet(i, prompt, control_task, seed_in, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold):
 
160
 
161
 
162
  def infer(prompt,video_in, control_task, seed_in, trim_value, ddim_steps, scale, low_threshold, high_threshold, value_threshold, distance_threshold, bg_threshold, gif_import):
163
+ if(is_shared_ui):
164
+ raise gr.Error("This Space doesn't work on this shared UI.")
165
  print(f"""
166
  β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
167
  {prompt}
 
255
  """
256
 
257
  with gr.Blocks(css='style.css') as demo:
258
+ if(is_shared_ui):
259
+ with gr.Box():
260
+ top_description = gr.HTML(f'''
261
+ <div class="gr-prose" style="max-width: 80%">
262
+ <h2 style="margin-top: 0">Attention - This Space doesn't work in this shared UI</h2>
263
+ <p>For it to work, you can access the <a href="https://huggingface.co/spaces/fffiloni/ControlNet-Video">original</a> or duplicate this Space and run it on your own profile using a GPU.&nbsp;&nbsp;<a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/{os.environ['SPACE_ID']}?duplicate=true"><img 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></p>
264
+ </div>
265
+ ''')
266
  with gr.Column(elem_id="col-container"):
267
  gr.HTML(title)
268
  gr.HTML("""
 
316
 
317
  with gr.Tab("Custom Model"):
318
  current_base_model = gr.Text(label='Current base model',
319
+ value="" if is_shared_ui else DEFAULT_BASE_MODEL_URL)
320
  with gr.Row():
321
  with gr.Column():
322
  base_model_repo = gr.Text(label='Base model repo',
323
  max_lines=1,
324
+ placeholder="" if is_shared_ui else DEFAULT_BASE_MODEL_REPO,
325
  interactive=True)
326
  base_model_filename = gr.Text(
327
  label='Base model file',
328
  max_lines=1,
329
+ placeholder="" if is_shared_ui else DEFAULT_BASE_MODEL_FILENAME,
330
  interactive=True)
331
  change_base_model_button = gr.Button('Change base model')
332
 
333
  gr.HTML(
334
  '''<p>You can use other base models by specifying the repository name and filename.<br />
335
  The base model must be compatible with Stable Diffusion v1.5.</p>''')
336
+ if(not is_shared_ui):
337
+ change_base_model_button.click(fn=model.set_base_model,
338
+ inputs=[
339
+ base_model_repo,
340
+ base_model_filename,
341
+ ],
342
+ outputs=current_base_model, queue=False)
343
 
344
  submit_btn = gr.Button("Generate ControlNet video")
345