huzey commited on
Commit
2b5e956
1 Parent(s): 1f0fa34
Files changed (3) hide show
  1. app.py +18 -2
  2. docker-compose.yml +22 -0
  3. requirements.txt +1 -1
app.py CHANGED
@@ -414,8 +414,11 @@ def run_fn(
414
  images = [tup[0] for tup in images]
415
  images = [transform_image(image, resolution=resolution) for image in images]
416
  images = torch.stack(images)
417
-
418
  model = load_model(model_name)
 
 
 
419
 
420
  kwargs = {
421
  "model_name": model_name,
@@ -593,7 +596,8 @@ def make_output_images_section():
593
 
594
  def make_parameters_section():
595
  gr.Markdown("### Parameters <a style='color: #0044CC;' href='https://ncut-pytorch.readthedocs.io/en/latest/how_to_get_better_segmentation/' target='_blank'>Help</a>")
596
- from ncut_pytorch.backbone import list_models, get_demo_model_names
 
597
  model_names = list_models()
598
  model_names = sorted(model_names)
599
  model_dropdown = gr.Dropdown(model_names, label="Backbone", value="DiNO(dino_vitb8_448)", elem_id="model_name")
@@ -602,6 +606,13 @@ def make_parameters_section():
602
  num_eig_slider = gr.Slider(1, 1000, step=1, label="NCUT: Number of eigenvectors", value=100, elem_id="num_eig", info='increase for more clusters')
603
 
604
  def change_layer_slider(model_name):
 
 
 
 
 
 
 
605
  layer_dict = LAYER_DICT
606
  if model_name in layer_dict:
607
  value = layer_dict[model_name]
@@ -657,6 +668,8 @@ with demo:
657
  logging_text = gr.Textbox("Logging information", label="Logging", elem_id="logging", type="text", placeholder="Logging information")
658
 
659
  clear_images_button.click(lambda x: ([], []), outputs=[input_gallery, output_gallery])
 
 
660
  submit_button.click(
661
  run_fn,
662
  inputs=[
@@ -917,3 +930,6 @@ if DOWNLOAD_ALL_MODELS_DATASETS:
917
  threading.Thread(target=download_all_datasets).start()
918
 
919
  demo.launch(share=True)
 
 
 
 
414
  images = [tup[0] for tup in images]
415
  images = [transform_image(image, resolution=resolution) for image in images]
416
  images = torch.stack(images)
417
+
418
  model = load_model(model_name)
419
+ if "stable" in model_name.lower() and "diffusion" in model_name.lower():
420
+ model.timestep = layer
421
+ layer = 1
422
 
423
  kwargs = {
424
  "model_name": model_name,
 
596
 
597
  def make_parameters_section():
598
  gr.Markdown("### Parameters <a style='color: #0044CC;' href='https://ncut-pytorch.readthedocs.io/en/latest/how_to_get_better_segmentation/' target='_blank'>Help</a>")
599
+ # from ncut_pytorch.backbone import list_models, get_demo_model_names
600
+ from backbone import list_models, get_demo_model_names
601
  model_names = list_models()
602
  model_names = sorted(model_names)
603
  model_dropdown = gr.Dropdown(model_names, label="Backbone", value="DiNO(dino_vitb8_448)", elem_id="model_name")
 
606
  num_eig_slider = gr.Slider(1, 1000, step=1, label="NCUT: Number of eigenvectors", value=100, elem_id="num_eig", info='increase for more clusters')
607
 
608
  def change_layer_slider(model_name):
609
+ # SD2, UNET
610
+ if "stable" in model_name.lower() and "diffusion" in model_name.lower():
611
+ from backbone import SD_KEY_DICT
612
+ default_layer = 'up_2_resnets_1_block' if 'diffusion-3' not in model_name else 'block_23'
613
+ return (gr.Slider(1, 49, step=1, label="Diffusion: Timestep (Noise)", value=5, elem_id="layer", visible=True, info="Noise level, 50 is max noise"),
614
+ gr.Dropdown(SD_KEY_DICT[model_name], label="Diffusion: Layer and Node", value=default_layer, elem_id="node_type", info="From the SD U-Net"))
615
+
616
  layer_dict = LAYER_DICT
617
  if model_name in layer_dict:
618
  value = layer_dict[model_name]
 
668
  logging_text = gr.Textbox("Logging information", label="Logging", elem_id="logging", type="text", placeholder="Logging information")
669
 
670
  clear_images_button.click(lambda x: ([], []), outputs=[input_gallery, output_gallery])
671
+
672
+
673
  submit_button.click(
674
  run_fn,
675
  inputs=[
 
930
  threading.Thread(target=download_all_datasets).start()
931
 
932
  demo.launch(share=True)
933
+
934
+
935
+ # %%
docker-compose.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: '3.8'
2
+
3
+ services:
4
+ ncut_demo:
5
+ image: registry.hf.space/huzey-ncut-pytorch:latest
6
+ container_name: ncut_demo
7
+ environment:
8
+ - HF_ACCESS_TOKEN=${HF_ACCESS_TOKEN}
9
+ - USE_HUGGINGFACE_ZEROGPU=false
10
+ ports:
11
+ - "7860:7860"
12
+ deploy:
13
+ resources:
14
+ reservations:
15
+ devices:
16
+ - capabilities: [gpu]
17
+ platform: linux/amd64
18
+ runtime: nvidia
19
+ shm_size: '64G'
20
+ command: python app.py
21
+ networks:
22
+ - default
requirements.txt CHANGED
@@ -1,6 +1,6 @@
1
  torch
2
  torchvision
3
- ncut-pytorch>=1.2.7
4
  opencv-python
5
  decord
6
  transformers
 
1
  torch
2
  torchvision
3
+ ncut-pytorch>=1.3.1
4
  opencv-python
5
  decord
6
  transformers