Skip to content

Commit

Permalink
Fix model cards from re-appearing in front scene tab (#29)
Browse files Browse the repository at this point in the history
Fix model cards from re-appearing in front scene tab

---------

Signed-off-by: Mingxin Zheng <[email protected]>
  • Loading branch information
mingxin-zheng authored Oct 22, 2024
1 parent 0d064d7 commit 1f62c40
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions monai_vila2d/demo/gradio_monai_vila2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
["Segment the visceral structures in the current image."],
["Can you identify any liver masses or tumors?"],
["Segment the entire image."],
["Describe the image in detail"],
]

EXAMPLE_PROMPTS_2D = [
Expand All @@ -90,6 +91,7 @@
["Is there evidence of cardiomegaly in this image?"],
["Is the atelectasis located on the left side or right side?"],
["What level is the cardiomegaly?"],
["Describe the image in detail"],
]

HTML_PLACEHOLDER = "<br>".join([""] * 15)
Expand Down Expand Up @@ -275,6 +277,7 @@ def __init__(self):
self.temp_working_dir = None
self.idx_range = (None, None)
self.interactive = False
self.sys_msgs_to_hide = []


def new_session_variables(**kwargs):
Expand Down Expand Up @@ -422,14 +425,14 @@ def process_prompt(self, prompt, sv, chat_history):
mod_msg = f"This is a {modality} image.\n" if modality != "Unknown" else ""

img_file = CACHED_IMAGES.get(sv.image_url, None)
sys_msgs_to_hide = []

if isinstance(img_file, str):
if "<image>" not in prompt:
_prompt = sv.sys_msg + "<image>" + mod_msg + prompt
sys_msgs_to_hide.append(sv.sys_msg + "<image>" + mod_msg)
sv.sys_msgs_to_hide.append(sv.sys_msg + "<image>" + mod_msg)
else:
_prompt = sv.sys_msg + mod_msg + prompt
sys_msgs_to_hide.append(sv.sys_msg + mod_msg)
sv.sys_msgs_to_hide.append(sv.sys_msg + mod_msg)

if img_file.endswith(".nii.gz"): # Take the specific slice from a volume
chat_history.append(
Expand Down Expand Up @@ -502,12 +505,13 @@ def process_prompt(self, prompt, sv, chat_history):
download_file_path=download_pkg,
temp_working_dir=sv.temp_working_dir,
interactive=True,
sys_msgs_to_hide=sv.sys_msgs_to_hide,
)
return (
None,
new_sv,
chat_history,
chat_history.get_html(show_all=False, sys_msgs_to_hide=sys_msgs_to_hide),
chat_history.get_html(show_all=False, sys_msgs_to_hide=sv.sys_msgs_to_hide),
chat_history.get_html(show_all=True),
)

Expand Down

0 comments on commit 1f62c40

Please sign in to comment.