Spaces:
Runtime error
Runtime error
Merge branch 'main' of https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything
Browse files- app.py +20 -7
- requirements.txt +3 -1
app.py
CHANGED
@@ -4,7 +4,7 @@ warnings.filterwarnings('ignore')
|
|
4 |
|
5 |
import subprocess, io, os, sys, time
|
6 |
os.system("pip install gradio==3.40.1")
|
7 |
-
# os.system("pip install transformers==4.
|
8 |
import gradio as gr
|
9 |
|
10 |
from loguru import logger
|
@@ -38,10 +38,17 @@ import cv2
|
|
38 |
import numpy as np
|
39 |
import matplotlib.pyplot as plt
|
40 |
|
|
|
|
|
41 |
ram_enable = True
|
|
|
42 |
kosmos_enable = False
|
43 |
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
try:
|
46 |
from lama_cleaner.model_manager import ModelManager
|
47 |
from lama_cleaner.schema import Config as lama_Config
|
@@ -796,7 +803,11 @@ def get_model_device(module):
|
|
796 |
except Exception as e:
|
797 |
return 'Error'
|
798 |
|
799 |
-
task_types = ["detection"
|
|
|
|
|
|
|
|
|
800 |
if lama_cleaner_enable:
|
801 |
task_types.append("remove")
|
802 |
if ram_enable:
|
@@ -808,7 +819,7 @@ if __name__ == "__main__":
|
|
808 |
parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
|
809 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
810 |
parser.add_argument("--share", action="store_true", help="share the app")
|
811 |
-
args = parser.
|
812 |
print(f'args = {args}')
|
813 |
|
814 |
if os.environ.get('IS_MY_DEBUG') is None:
|
@@ -816,15 +827,17 @@ if __name__ == "__main__":
|
|
816 |
|
817 |
set_device()
|
818 |
|
819 |
-
if
|
820 |
kosmos_model, kosmos_processor = load_kosmos_model(device)
|
821 |
|
822 |
load_groundingdino_model()
|
823 |
-
|
|
|
824 |
get_sam_vit_h_4b8939()
|
825 |
load_sam_model()
|
826 |
|
827 |
-
|
|
|
828 |
|
829 |
if lama_cleaner_enable:
|
830 |
load_lama_cleaner_model()
|
|
|
4 |
|
5 |
import subprocess, io, os, sys, time
|
6 |
os.system("pip install gradio==3.40.1")
|
7 |
+
# os.system("pip install transformers==4.31.0")
|
8 |
import gradio as gr
|
9 |
|
10 |
from loguru import logger
|
|
|
38 |
import numpy as np
|
39 |
import matplotlib.pyplot as plt
|
40 |
|
41 |
+
sam_enable = True
|
42 |
+
inpainting_enable = True
|
43 |
ram_enable = True
|
44 |
+
lama_cleaner_enable = True
|
45 |
kosmos_enable = False
|
46 |
|
47 |
+
if os.environ.get('IS_MY_DEBUG') is not None:
|
48 |
+
sam_enable = False
|
49 |
+
inpainting_enable = False
|
50 |
+
kosmos_enable = False
|
51 |
+
|
52 |
try:
|
53 |
from lama_cleaner.model_manager import ModelManager
|
54 |
from lama_cleaner.schema import Config as lama_Config
|
|
|
803 |
except Exception as e:
|
804 |
return 'Error'
|
805 |
|
806 |
+
task_types = ["detection"]
|
807 |
+
if sam_enable:
|
808 |
+
task_types.append("segment")
|
809 |
+
if inpainting_enable:
|
810 |
+
task_types.append("inpainting")
|
811 |
if lama_cleaner_enable:
|
812 |
task_types.append("remove")
|
813 |
if ram_enable:
|
|
|
819 |
parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
|
820 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
821 |
parser.add_argument("--share", action="store_true", help="share the app")
|
822 |
+
args, _ = parser.parse_known_args()
|
823 |
print(f'args = {args}')
|
824 |
|
825 |
if os.environ.get('IS_MY_DEBUG') is None:
|
|
|
827 |
|
828 |
set_device()
|
829 |
|
830 |
+
if kosmos_enable:
|
831 |
kosmos_model, kosmos_processor = load_kosmos_model(device)
|
832 |
|
833 |
load_groundingdino_model()
|
834 |
+
|
835 |
+
if sam_enable:
|
836 |
get_sam_vit_h_4b8939()
|
837 |
load_sam_model()
|
838 |
|
839 |
+
if inpainting_enable:
|
840 |
+
load_sd_model()
|
841 |
|
842 |
if lama_cleaner_enable:
|
843 |
load_lama_cleaner_model()
|
requirements.txt
CHANGED
@@ -30,5 +30,7 @@ lama-cleaner==1.2.3
|
|
30 |
# transformers==4.32.0
|
31 |
# transformers@git+https://github.com/huggingface/transformers.git@main
|
32 |
|
33 |
-
openmim==0.3.9
|
34 |
mmcv==2.0.0
|
|
|
|
|
|
|
|
30 |
# transformers==4.32.0
|
31 |
# transformers@git+https://github.com/huggingface/transformers.git@main
|
32 |
|
|
|
33 |
mmcv==2.0.0
|
34 |
+
mmengine
|
35 |
+
openmim==0.3.9
|
36 |
+
|