Spaces:
Paused
Paused
File size: 10,383 Bytes
4a7650f 17b483c 7638e59 4a7650f df6cb9a 17b483c df6cb9a 8e4d777 df6cb9a d9bc917 df6cb9a 8e4d777 df6cb9a d9bc917 5191921 d9bc917 95f68f8 d9bc917 156ba8e df6cb9a 95f68f8 df6cb9a 95f68f8 d9bc917 4a7650f 17b483c 4a7650f 17b483c df6cb9a 17b483c d9bc917 156ba8e b50372e 7638e59 b50372e 17b483c b50372e 17b483c 7638e59 17b483c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
import streamlit as st
import time
from diffusers import DiffusionPipeline
import matplotlib.pyplot as plt
import torch
if 'button_clicked' not in st.session_state:
st.session_state.button_clicked = False
# Define a function to handle the button click
def on_button_click():
st.session_state.button_clicked = True
modalities = [
"COMPUTED TOMOGRAPHY (CT)", "DIGITAL BREAST TOMOSYNTHESIS", "DIGITAL MAMMOGRAPHY",
"MAGNETIC RESONANCE IMAGING (MRI)", "MICRO-CT", "PET-CT",
"POSITRON EMISSION TOMOGRAPHY (PET)", "RADIOGRAPHY", "ULTRASONOGRAPHY"
]
modalities = [i.lower() for i in modalities]
organs = [
"ANUS", "AORTA", "BLADDER", "BONE", "BRAIN", "BREAST", "CERVIX", "CHEST", "COLON",
"CORONARY HEART", "EAR", "ENDOMETRIUM", "ESOPHAGUS", "HEAD AND NECK", "KIDNEY", "LIVER",
"LUNG", "LYMPH NODE", "OVARY", "PANCREAS", "PELVIS", "PERIPHERAL ARTERIAL", "PHANTOM",
"PROSTATE", "RECTUM", "SOFT TISSUES", "UTERUS"
]
organs = [i.lower() for i in organs]
artists = [
"Leonardo da Vinci", "Vincent van Gogh", "Pablo Picasso", "Claude Monet", "Rembrandt",
"Michelangelo", "Raphael", "Henri Matisse", "Paul Cezanne", "Gustav Klimt",
"Jackson Pollock", "Edgar Degas", "Francisco Goya", "Edouard Manet", "Andy Warhol",
"Salvador Dal铆", "Wassily Kandinsky", "Paul Gauguin", "Joan Mir贸", "Georges Seurat",
"脡douard Vuillard", "Marc Chagall", "Kazimir Malevich", "Piet Mondrian", "Jean-Michel Basquiat",
"Frida Kahlo", "Artemisia Gentileschi", "Caravaggio", "El Greco", "Eug猫ne Delacroix",
"J.M.W. Turner"
]
st.markdown("<div style=\"text-align: center;\"> <img src=\"https://www.deeptracetech.com/images/graphical-verbose-logo-inline.png\" alt=\"DeepTrace Technologies logo\" width=\"208\" height=\"100\"></div>",
unsafe_allow_html=True)
st.markdown("<h1 style='text-align: center;'>Paint your medical image as a great master would!</h1>", unsafe_allow_html=True)
#st.title("Paint your medical image as a great master would!")
organ = st.selectbox('Organ', organs, index=None)
modality = st.selectbox('Modality', modalities, index=None)
style = st.selectbox('Style', artists, index=None)
image_descriptions = {
"COMPUTED TOMOGRAPHY (CT)": "CT scan",
"DIGITAL BREAST TOMOSYNTHESIS": "3D breast tomosynthesis image",
"DIGITAL MAMMOGRAPHY": "digital mammography image",
"MAGNETIC RESONANCE IMAGING (MRI)": "MRI scan",
"MICRO-CT": "micro-CT scan",
"PET-CT": "PET-CT scan",
"POSITRON EMISSION TOMOGRAPHY (PET)": "PET scan",
"RADIOGRAPHY": "radiography image",
"ULTRASONOGRAPHY": "ultrasonography image"
}
organ_descriptions = {
"ANUS": "of the anus, focusing on musculature and surrounding tissues",
"AORTA": "of the aorta, capturing the main artery and branches",
"BLADDER": "of the bladder, emphasizing its structure",
"BONE": "of the bone, showcasing its structure",
"BRAIN": "of the brain, highlighting its structures",
"BREAST": "of the breast, focusing on its anatomy",
"CERVIX": "of the cervix, capturing its features",
"CHEST": "of the chest, showcasing thoracic cavity",
"COLON": "of the colon, emphasizing its structure",
"CORONARY HEART": "of the coronary heart, highlighting coronary arteries",
"EAR": "of the ear, focusing on outer, middle, and inner ear",
"ENDOMETRIUM": "of the endometrium, highlighting uterine lining",
"ESOPHAGUS": "of the esophagus, emphasizing its structure",
"HEAD AND NECK": "of the head and neck, showcasing anatomical structures",
"KIDNEY": "of the kidney, focusing on internal structure",
"LIVER": "of the liver, highlighting its lobes",
"LUNG": "of the lung, showcasing respiratory anatomy",
"LYMPH NODE": "of the lymph node, emphasizing anatomical features",
"OVARY": "of the ovary, highlighting internal structures",
"PANCREAS": "of the pancreas, showcasing its structure",
"PELVIS": "of the pelvis, focusing on bone structure",
"PERIPHERAL ARTERIAL": "of the peripheral arterial system, highlighting vascular structures",
"PHANTOM": "of a phantom, focusing on simulated features",
"PROSTATE": "of the prostate, emphasizing its structure",
"RECTUM": "of the rectum, highlighting its anatomy",
"SOFT TISSUES": "of the soft tissues, showcasing detailed anatomy",
"UTERUS": "of the uterus, emphasizing its structure"
}
if organ != None:
organ_description = organ_descriptions[organ.upper()]
if modality != None:
image_description = image_descriptions[modality.upper()]
artist_prompts = {
"Leonardo da Vinci": "Generate a detailed {image_description} {organ_description} in the style of Leonardo da Vinci. Emphasize anatomical precision with Renaissance aesthetics.",
"Vincent van Gogh": "Create a {image_description} {organ_description} in the style of Vincent van Gogh. Use bold brushstrokes and vibrant colors.",
"Pablo Picasso": "Produce a {image_description} {organ_description} in the style of Pablo Picasso. Use cubist elements and abstract shapes.",
"Claude Monet": "Generate a {image_description} {organ_description} in the style of Claude Monet. Use soft colors and diffused light.",
"Rembrandt": "Create a {image_description} {organ_description} in the style of Rembrandt. Emphasize dramatic lighting and contrasts.",
"Michelangelo": "Produce a {image_description} {organ_description} in the style of Michelangelo. Emphasize anatomical detail and sculptural quality.",
"Raphael": "Generate an accurate {image_description} {organ_description} in the style of Raphael. Use harmonious compositions and delicate lines.",
"Henri Matisse": "Create a {image_description} {organ_description} in the style of Henri Matisse. Use bold colors and simplified forms.",
"Paul Cezanne": "Produce a {image_description} {organ_description} in the style of Paul Cezanne. Use geometric simplification and structured forms.",
"Gustav Klimt": "Generate a {image_description} {organ_description} in the style of Gustav Klimt. Incorporate intricate patterns and a decorative quality.",
"Jackson Pollock": "Create a {image_description} {organ_description} in the style of Jackson Pollock. Use energetic splatters and abstract layers.",
"Edgar Degas": "Produce a {image_description} {organ_description} in the style of Edgar Degas. Use soft pastels and delicate lines.",
"Francisco Goya": "Generate a {image_description} {organ_description} in the style of Francisco Goya. Emphasize strong contrasts and a somber tone.",
"Edouard Manet": "Create a {image_description} {organ_description} in the style of Edouard Manet. Use loose brushstrokes and focus on light and shadow.",
"Andy Warhol": "Produce a {image_description} {organ_description} in the style of Andy Warhol. Use bright colors and a graphic aesthetic.",
"Salvador Dal铆": "Generate a {image_description} {organ_description} in the style of Salvador Dal铆. Incorporate surreal elements and distorted forms.",
"Wassily Kandinsky": "Create a {image_description} {organ_description} in the style of Wassily Kandinsky. Use vibrant colors and geometric shapes.",
"Paul Gauguin": "Produce a {image_description} {organ_description} in the style of Paul Gauguin. Use bold colors and strong outlines.",
"Joan Mir贸": "Generate a {image_description} {organ_description} in the style of Joan Mir贸. Use playful shapes and bright colors.",
"Georges Seurat": "Create an accurate {image_description} {organ_description} in the style of Georges Seurat. Use pointillism with tiny dots of color.",
"脡douard Vuillard": "Produce a {image_description} {organ_description} in the style of 脡douard Vuillard. Use soft colors and intricate patterns.",
"Marc Chagall": "Generate a {image_description} {organ_description} in the style of Marc Chagall. Use rich colors and fantastical elements.",
"Kazimir Malevich": "Create an accurate {image_description} {organ_description} in the style of Kazimir Malevich. Use geometric shapes and minimalism.",
"Piet Mondrian": "Produce a {image_description} {organ_description} in the style of Piet Mondrian. Use clean lines and primary colors.",
"Jean-Michel Basquiat": "Generate a {image_description} {organ_description} in the style of Jean-Michel Basquiat. Use bold lines and graffiti elements.",
"Frida Kahlo": "Create an accurate {image_description} {organ_description} in the style of Frida Kahlo. Use rich colors and symbolic elements.",
"Artemisia Gentileschi": "Produce a {image_description} {organ_description} in the style of Artemisia Gentileschi. Use strong contrasts and rich colors.",
"Caravaggio": "Generate a {image_description} {organ_description} in the style of Caravaggio. Use dramatic lighting and meticulous detail.",
"El Greco": "Create a {image_description} {organ_description} in the style of El Greco. Use elongated forms and dramatic color.",
"Eug猫ne Delacroix": "Produce a {image_description} {organ_description} in the style of Eug猫ne Delacroix. Use vivid colors and energetic brushstrokes.",
"J.M.W. Turner": "Generate a {image_description} {organ_description} in the style of J.M.W. Turner. Use soft light and swirling colors."
}
combined_prompts = {artist: prompt.replace("{image_description}", "{image_description}").replace("{organ_description}", "{organ_description}")
for artist, prompt in artist_prompts.items()}
prompt_lst = [organ, modality, style]
if None not in prompt_lst:
st.session_state.button_disabled = False
else:
st.session_state.button_disabled = True
if st.session_state.button_clicked:
st.session_state.button_disabled = True
st.session_state.button_clicked = False
st.button('Submit', disabled=st.session_state.button_disabled)
with st.spinner('Processing...'):
print(prompt_lst)
prompt = combined_prompts[style].format(image_description=image_description, organ_description=organ_description)
print(prompt)
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16")
pipe.to("cuda")
image = pipe(prompt=prompt).images[0]
st.image(image)
st.session_state.button_disabled = False
else:
st.button('Submit', on_click=on_button_click, disabled=st.session_state.button_disabled) |