aelius commited on
Commit
df6cb9a
1 Parent(s): 17b483c

added momdalities, organs and artists + buillt-in prompt engeneering

Browse files
Files changed (1) hide show
  1. app.py +71 -6
app.py CHANGED
@@ -4,6 +4,7 @@ from diffusers import DiffusionPipeline
4
  import matplotlib.pyplot as plt
5
  import torch
6
 
 
7
  if 'button_clicked' not in st.session_state:
8
  st.session_state.button_clicked = False
9
 
@@ -11,9 +12,74 @@ if 'button_clicked' not in st.session_state:
11
  def on_button_click():
12
  st.session_state.button_clicked = True
13
 
14
- organ = st.selectbox('Organ', ['Brain', 'Thorax'], index=None)
15
- modality = st.selectbox('Modality', ['Magnetic Resonance Imaging', 'Computed Tomography'], index=None)
16
- style = st.selectbox('Style', ['Picasso', 'Van Gogh'], index=None)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  prompt_lst = [organ, modality, style]
19
 
@@ -28,13 +94,12 @@ if st.session_state.button_clicked:
28
  st.session_state.button_clicked = False
29
  st.button('Submit', disabled=st.session_state.button_disabled)
30
  with st.spinner('Processing...'):
31
- prompt = ','.join(prompt_lst)
32
- print(prompt)
33
 
 
34
  pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16")
35
  pipe.to("cuda")
36
 
37
- prompt += " high resolution, photorealistic"
38
  image = pipe(prompt=prompt).images[0]
39
 
40
  st.image(image)
 
4
  import matplotlib.pyplot as plt
5
  import torch
6
 
7
+
8
  if 'button_clicked' not in st.session_state:
9
  st.session_state.button_clicked = False
10
 
 
12
  def on_button_click():
13
  st.session_state.button_clicked = True
14
 
15
+
16
+ modalities = [
17
+ "COMPUTED TOMOGRAPHY (CT)", "DIGITAL BREAST TOMOSYNTHESIS", "DIGITAL MAMMOGRAPHY",
18
+ "MAGNETIC RESONANCE IMAGING (MRI)", "MICRO-CT", "PET-CT",
19
+ "POSITRON EMISSION TOMOGRAPHY (PET)", "RADIOGRAPHY", "ULTRASONOGRAPHY"
20
+ ]
21
+
22
+ modalities = [i.lower() for i in modalities]
23
+
24
+ organs = [
25
+ "ANUS", "AORTA", "BLADDER", "BONE", "BRAIN", "BREAST", "CERVIX", "CHEST", "COLON",
26
+ "CORONARY HEART", "EAR", "ENDOMETRIUM", "ESOPHAGUS", "HEAD AND NECK", "KIDNEY", "LIVER",
27
+ "LUNG", "LYMPH NODE", "OVARY", "PANCREAS", "PELVIS", "PERIPHERAL ARTERIAL", "PHANTOM",
28
+ "PROSTATE", "RECTUM", "SOFT TISSUES", "UTERUS"
29
+ ]
30
+
31
+ organs = [i.lower() for i in organs]
32
+
33
+ artists = [
34
+ "Leonardo da Vinci", "Vincent van Gogh", "Pablo Picasso", "Claude Monet", "Rembrandt",
35
+ "Michelangelo", "Raphael", "Henri Matisse", "Paul Cezanne", "Gustav Klimt",
36
+ "Jackson Pollock", "Edgar Degas", "Francisco Goya", "Edouard Manet", "Andy Warhol",
37
+ "Salvador Dal铆", "Wassily Kandinsky", "Paul Gauguin", "Joan Mir贸", "Georges Seurat",
38
+ "脡douard Vuillard", "Marc Chagall", "Kazimir Malevich", "Piet Mondrian", "Jean-Michel Basquiat",
39
+ "Frida Kahlo", "Artemisia Gentileschi", "Caravaggio", "El Greco", "Eug猫ne Delacroix",
40
+ "J.M.W. Turner"
41
+ ]
42
+
43
+
44
+ organ = st.selectbox('Organ', organs, index=None)
45
+ modality = st.selectbox('Modality', modalities, index=None)
46
+ style = st.selectbox('Style', artists, index=None)
47
+
48
+ artist_prompts = {
49
+ 'Leonardo da Vinci': f"A detailed {organ} {modality} in the intricate and detailed style of Leonardo da Vinci's anatomical drawings. The {modality} should show the {organ} structure with medical precision, combining scientific accuracy with Renaissance artistry.",
50
+ 'Vincent van Gogh': f"A detailed {organ} {modality} in the style of Van Gogh, with the swirling, vibrant colors and bold brushstrokes characteristic of his paintings. The {modality} should show the {organ} structure with medical precision, set against a background reminiscent of 'Starry Night.'",
51
+ 'Pablo Picasso': f"A detailed {organ} {modality} depicted in the abstract and fragmented style of Pablo Picasso's Cubism. The {modality} should show the {organ} structure with medical precision, using geometric shapes and bold lines.",
52
+ 'Claude Monet': f"A detailed {organ} {modality} in the impressionistic and soft-focus style of Claude Monet. The {modality} should show the {organ} structure with medical precision, using delicate brushstrokes and a subtle color palette.",
53
+ 'Rembrandt': f"A detailed {organ} {modality} rendered in the dramatic and richly textured style of Rembrandt. The {modality} should show the {organ} structure with medical precision, using deep shadows and warm highlights.",
54
+ 'Michelangelo': f"A detailed {organ} {modality} sculpted in the grand and dynamic style of Michelangelo. The {modality} should show the {organ} structure with medical precision, emphasizing intricate details and a sense of movement.",
55
+ 'Raphael': f"A detailed {organ} {modality} in the harmonious and balanced style of Raphael. The {modality} should show the {organ} structure with medical precision, using clear lines and soft colors.",
56
+ 'Henri Matisse': f"A detailed {organ} {modality} in the vibrant and expressive style of Henri Matisse. The {modality} should show the {organ} structure with medical precision, using bold colors and fluid lines.",
57
+ 'Paul Cezanne': f"A detailed {organ} {modality} in the structured and methodical style of Paul Cezanne. The {modality} should show the {organ} structure with medical precision, using carefully arranged shapes and a harmonious color palette.",
58
+ 'Gustav Klimt': f"A detailed {organ} {modality} in the ornate and decorative style of Gustav Klimt. The {modality} should show the {organ} structure with medical precision, using intricate patterns, gold leaf, and symbolic elements.",
59
+ 'Jackson Pollock': f"A detailed {organ} {modality} in the chaotic and energetic style of Jackson Pollock's action painting. The {modality} should show the {organ} structure with medical precision, using splatters and drips of paint.",
60
+ 'Edgar Degas': f"A detailed {organ} {modality} in the graceful and observational style of Edgar Degas. The {modality} should show the {organ} structure with medical precision, using delicate lines and soft pastels.",
61
+ 'Francisco Goya': f"A detailed {organ} {modality} in the dark and dramatic style of Francisco Goya. The {modality} should show the {organ} structure with medical precision, using stark contrasts and a haunting atmosphere.",
62
+ 'Edouard Manet': f"A detailed {organ} {modality} in the bold and modern style of Edouard Manet. The {modality} should show the {organ} structure with medical precision, using strong contrasts and a focus on contemporary realism.",
63
+ 'Andy Warhol': f"A detailed {organ} {modality} in the pop art style of Andy Warhol. The {modality} should show the {organ} structure with medical precision, using bright colors, repetitive patterns, and a playful, commercial aesthetic.",
64
+ 'Salvador Dal铆': f"A detailed {organ} {modality} in the surreal and dreamlike style of Salvador Dal铆. The {modality} should show the {organ} structure with medical precision, incorporating fantastical elements and imaginative twists.",
65
+ 'Wassily Kandinsky': f"A detailed {organ} {modality} in the abstract and colorful style of Wassily Kandinsky. The {modality} should show the {organ} structure with medical precision, using vibrant hues and geometric shapes.",
66
+ 'Paul Gauguin': f"A detailed {organ} {modality} in the exotic and symbolic style of Paul Gauguin. The {modality} should show the {organ} structure with medical precision, using rich colors and simplified forms.",
67
+ 'Joan Mir贸': f"A detailed {organ} {modality} in the playful and abstract style of Joan Mir贸. The {modality} should show the {organ} structure with medical precision, using whimsical shapes and bright colors.",
68
+ 'Georges Seurat': f"A detailed {organ} {modality} in the pointillist style of Georges Seurat. The {modality} should show the {organ} structure with medical precision, using tiny dots of color meticulously arranged.",
69
+ '脡douard Vuillard': f"A detailed {organ} {modality} in the intimate and decorative style of 脡douard Vuillard. The {modality} should show the {organ} structure with medical precision, using soft colors and intricate patterns.",
70
+ 'Marc Chagall': f"A detailed {organ} {modality} in the dreamlike and fantastical style of Marc Chagall. The {modality} should show the {organ} structure with medical precision, using floating figures and vivid colors.",
71
+ 'Kazimir Malevich': f"A detailed {organ} {modality} in the minimalist and geometric style of Kazimir Malevich. The {modality} should show the {organ} structure with medical precision, using simple shapes and pure colors.",
72
+ 'Piet Mondrian': f"A detailed {organ} {modality} in the neoplasticist style of Piet Mondrian. The {modality} should show the {organ} structure with medical precision, using a grid of black lines and primary colors.",
73
+ 'Jean-Michel Basquiat': f"A detailed {organ} {modality} in the raw and expressive style of Jean-Michel Basquiat. The {modality} should show the {organ} structure with medical precision, using bold lines and graffiti-like elements.",
74
+ 'Frida Kahlo': f"A detailed {organ} {modality} in the deeply personal and symbolic style of Frida Kahlo. The {modality} should show the {organ} structure with medical precision, using vivid colors and emotional intensity.",
75
+ 'Artemisia Gentileschi': f"A detailed {organ} {modality} in the dramatic and powerful style of Artemisia Gentileschi. The {modality} should show the {organ} structure with medical precision, using strong contrasts and dynamic composition.",
76
+ 'Caravaggio': f"A detailed {organ} {modality} in the intense and chiaroscuro style of Caravaggio. The {modality} should show the {organ} structure with medical precision, using stark lighting and dramatic shadows.",
77
+ 'El Greco': f"A detailed {organ} {modality} in the elongated and expressive style of El Greco. The {modality} should show the {organ} structure with medical precision, using distorted forms and vibrant colors.",
78
+ 'Eug猫ne Delacroix': f"A detailed {organ} {modality} in the romantic and dynamic style of Eug猫ne Delacroix. The {modality} should show the {organ} structure with medical precision, using bold colors and energetic brushstrokes.",
79
+ 'J.M.W. Turner': f"A detailed {organ} {modality} in the atmospheric and luminous style of J.M.W. Turner. The {modality} should show the {organ} structure with medical precision, using soft, swirling colors and a sense of light and movement."
80
+ }
81
+
82
+
83
 
84
  prompt_lst = [organ, modality, style]
85
 
 
94
  st.session_state.button_clicked = False
95
  st.button('Submit', disabled=st.session_state.button_disabled)
96
  with st.spinner('Processing...'):
97
+ print(prompt_lst)
 
98
 
99
+ prompt = artist_prompts[style]
100
  pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16")
101
  pipe.to("cuda")
102
 
 
103
  image = pipe(prompt=prompt).images[0]
104
 
105
  st.image(image)