Spaces:
Running
on
T4
Running
on
T4
liuyizhang
commited on
Commit
•
9912950
1
Parent(s):
bd50af0
Kosmos error: Memory limit exceeded
Browse files
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.36.1")
|
7 |
-
os.system("pip install gradio==3.
|
8 |
import gradio as gr
|
9 |
|
10 |
from loguru import logger
|
@@ -698,6 +698,8 @@ def run_anything_task(input_image, text_prompt, task_type, inpaint_prompt, box_t
|
|
698 |
logger.info(f'run_anything_task_[{file_temp}]_9_9_')
|
699 |
return output_images, gr.Gallery.update(label='result images'), None, None, None
|
700 |
|
|
|
|
|
701 |
def change_radio_display(task_type, mask_source_radio):
|
702 |
text_prompt_visible = True
|
703 |
inpaint_prompt_visible = False
|
@@ -710,21 +712,23 @@ def change_radio_display(task_type, mask_source_radio):
|
|
710 |
kosmos_text_output_visible = False
|
711 |
|
712 |
if task_type == "Kosmos-2":
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
if
|
726 |
text_prompt_visible = False
|
727 |
-
|
|
|
|
|
728 |
|
729 |
return (gr.Textbox.update(visible=text_prompt_visible),
|
730 |
gr.Textbox.update(visible=inpaint_prompt_visible),
|
@@ -750,6 +754,10 @@ def get_model_device(module):
|
|
750 |
except Exception as e:
|
751 |
return 'Error'
|
752 |
|
|
|
|
|
|
|
|
|
753 |
if __name__ == "__main__":
|
754 |
parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
|
755 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
@@ -768,7 +776,7 @@ if __name__ == "__main__":
|
|
768 |
load_lama_cleaner_model()
|
769 |
load_ram_model()
|
770 |
|
771 |
-
if os.environ.get('IS_MY_DEBUG') is None:
|
772 |
kosmos_model, kosmos_processor = load_kosmos_model(device)
|
773 |
|
774 |
if os.environ.get('IS_MY_DEBUG') is None:
|
@@ -779,13 +787,14 @@ if __name__ == "__main__":
|
|
779 |
print(f'sd_model__{get_model_device(sd_model)}')
|
780 |
print(f'lama_cleaner_model__{get_model_device(lama_cleaner_model)}')
|
781 |
print(f'ram_model__{get_model_device(ram_model)}')
|
|
|
782 |
|
783 |
block = gr.Blocks().queue()
|
784 |
with block:
|
785 |
with gr.Row():
|
786 |
with gr.Column():
|
787 |
input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload")
|
788 |
-
task_type = gr.Radio(
|
789 |
label='Task type', visible=True)
|
790 |
mask_source_radio = gr.Radio([mask_source_draw, mask_source_segment],
|
791 |
value=mask_source_segment, label="Mask from",
|
@@ -860,7 +869,8 @@ if __name__ == "__main__":
|
|
860 |
DESCRIPTION = f'### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
861 |
DESCRIPTION += f'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
|
862 |
DESCRIPTION += f'Remove(cleaner) from [lama-cleaner](https://github.com/Sanster/lama-cleaner). <br>'
|
863 |
-
|
|
|
864 |
DESCRIPTION += f'Thanks for their excellent work.'
|
865 |
DESCRIPTION += f'<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. \
|
866 |
<a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|
|
|
4 |
|
5 |
import subprocess, io, os, sys, time
|
6 |
# os.system("pip install gradio==3.36.1")
|
7 |
+
os.system("pip install gradio==3.40.1")
|
8 |
import gradio as gr
|
9 |
|
10 |
from loguru import logger
|
|
|
698 |
logger.info(f'run_anything_task_[{file_temp}]_9_9_')
|
699 |
return output_images, gr.Gallery.update(label='result images'), None, None, None
|
700 |
|
701 |
+
kosmos_enable = False
|
702 |
+
|
703 |
def change_radio_display(task_type, mask_source_radio):
|
704 |
text_prompt_visible = True
|
705 |
inpaint_prompt_visible = False
|
|
|
712 |
kosmos_text_output_visible = False
|
713 |
|
714 |
if task_type == "Kosmos-2":
|
715 |
+
if kosmos_enable:
|
716 |
+
text_prompt_visible = False
|
717 |
+
image_gallery_visible = False
|
718 |
+
kosmos_input_visible = True
|
719 |
+
kosmos_output_visible = True
|
720 |
+
kosmos_text_output_visible = True
|
721 |
+
|
722 |
+
|
723 |
+
if task_type == "inpainting":
|
724 |
+
inpaint_prompt_visible = True
|
725 |
+
if task_type == "inpainting" or task_type == "remove":
|
726 |
+
mask_source_radio_visible = True
|
727 |
+
if mask_source_radio == mask_source_draw:
|
728 |
text_prompt_visible = False
|
729 |
+
if task_type == "relate anything":
|
730 |
+
text_prompt_visible = False
|
731 |
+
num_relation_visible = True
|
732 |
|
733 |
return (gr.Textbox.update(visible=text_prompt_visible),
|
734 |
gr.Textbox.update(visible=inpaint_prompt_visible),
|
|
|
754 |
except Exception as e:
|
755 |
return 'Error'
|
756 |
|
757 |
+
task_types = ["detection", "segment", "inpainting", "remove", "relate anything"]
|
758 |
+
if kosmos_enable:
|
759 |
+
task_types.append("Kosmos-2")
|
760 |
+
|
761 |
if __name__ == "__main__":
|
762 |
parser = argparse.ArgumentParser("Grounded SAM demo", add_help=True)
|
763 |
parser.add_argument("--debug", action="store_true", help="using debug mode")
|
|
|
776 |
load_lama_cleaner_model()
|
777 |
load_ram_model()
|
778 |
|
779 |
+
if os.environ.get('IS_MY_DEBUG') is None and kosmos_enable:
|
780 |
kosmos_model, kosmos_processor = load_kosmos_model(device)
|
781 |
|
782 |
if os.environ.get('IS_MY_DEBUG') is None:
|
|
|
787 |
print(f'sd_model__{get_model_device(sd_model)}')
|
788 |
print(f'lama_cleaner_model__{get_model_device(lama_cleaner_model)}')
|
789 |
print(f'ram_model__{get_model_device(ram_model)}')
|
790 |
+
print(f'kosmos_model__{get_model_device(kosmos_model)}')
|
791 |
|
792 |
block = gr.Blocks().queue()
|
793 |
with block:
|
794 |
with gr.Row():
|
795 |
with gr.Column():
|
796 |
input_image = gr.Image(source='upload', elem_id="image_upload", tool='sketch', type='pil', label="Upload")
|
797 |
+
task_type = gr.Radio(task_types, value="detection",
|
798 |
label='Task type', visible=True)
|
799 |
mask_source_radio = gr.Radio([mask_source_draw, mask_source_segment],
|
800 |
value=mask_source_segment, label="Mask from",
|
|
|
869 |
DESCRIPTION = f'### This demo from [Grounded-Segment-Anything](https://github.com/IDEA-Research/Grounded-Segment-Anything). <br>'
|
870 |
DESCRIPTION += f'RAM from [RelateAnything](https://github.com/Luodian/RelateAnything). <br>'
|
871 |
DESCRIPTION += f'Remove(cleaner) from [lama-cleaner](https://github.com/Sanster/lama-cleaner). <br>'
|
872 |
+
if kosmos_enable:
|
873 |
+
DESCRIPTION += f'Kosmos-2 from [Kosmos-2](https://huggingface.co/spaces/ydshieh/Kosmos-2). <br>'
|
874 |
DESCRIPTION += f'Thanks for their excellent work.'
|
875 |
DESCRIPTION += f'<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings. \
|
876 |
<a href="https://huggingface.co/spaces/yizhangliu/Grounded-Segment-Anything?duplicate=true"><img style="display: inline; margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space" /></a></p>'
|