awacke1 commited on
Commit
c8dc6c4
1 Parent(s): 7c570b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -11
app.py CHANGED
@@ -24,10 +24,12 @@ def save_image(img, prompt):
24
  unique_name = str(uuid.uuid4()) + ".png"
25
  img.save(unique_name)
26
 
27
- # save with prompt to save prompt as image file name
28
  filename = f"{prompt}.png"
29
  img.save(filename)
30
  return filename
 
 
31
 
32
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
33
  if randomize_seed:
@@ -44,6 +46,7 @@ MAX_SEED = np.iinfo(np.int32).max
44
  USE_TORCH_COMPILE = 0
45
  ENABLE_CPU_OFFLOAD = 0
46
 
 
47
  if torch.cuda.is_available():
48
  pipe = StableDiffusionXLPipeline.from_pretrained(
49
  "fluently/Fluently-XL-v4",
@@ -52,10 +55,13 @@ if torch.cuda.is_available():
52
  )
53
  pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
54
 
 
55
  pipe.load_lora_weights("ehristoforu/dalle-3-xl-v2", weight_name="dalle-3-xl-lora-v2.safetensors", adapter_name="dalle")
56
  pipe.set_adapters("dalle")
57
 
58
  pipe.to("cuda")
 
 
59
 
60
  @spaces.GPU(enable_queue=True)
61
  def generate(
@@ -65,10 +71,15 @@ def generate(
65
  seed: int = 0,
66
  width: int = 1024,
67
  height: int = 1024,
 
 
68
  guidance_scale: float = 3,
 
69
  randomize_seed: bool = False,
70
  progress=gr.Progress(track_tqdm=True),
71
  ):
 
 
72
  seed = int(randomize_seed_fn(seed, randomize_seed))
73
 
74
  if not use_negative_prompt:
@@ -81,25 +92,41 @@ def generate(
81
  height=height,
82
  guidance_scale=guidance_scale,
83
  num_inference_steps=20,
 
84
  num_images_per_prompt=1,
 
85
  cross_attention_kwargs={"scale": 0.65},
86
  output_type="pil",
87
  ).images
88
  image_paths = [save_image(img, prompt) for img in images]
 
 
89
  download_links = [create_download_link(path) for path in image_paths]
90
 
91
  print(image_paths)
 
92
  return image_paths, seed, download_links
93
 
 
 
 
 
 
 
 
 
 
94
  examples = [
95
- "An elderly man engages in a virtual reality physical therapy session, guided by a compassionate AI therapist that adapts the exercises to his abilities and provides encouragement, all from the comfort of his own home.",
96
- "In a bright, welcoming dental office, a young patient watches in awe as a dental robot efficiently and painlessly repairs a cavity using a laser system, while the dentist explains the procedure using interactive 3D images.",
97
- "A team of biomedical engineers collaborate in a state-of-the-art research facility, designing and testing advanced prosthetic limbs that seamlessly integrate with the patient's nervous system for natural, intuitive control.",
98
- "A pregnant woman undergoes a routine check-up, as a gentle robotic ultrasound system captures high-resolution 3D images of her developing baby, while the obstetrician provides reassurance and guidance via a holographic display.",
99
- "In a cutting-edge cancer treatment center, a patient undergoes a precision radiation therapy session, where an AI-guided system delivers highly targeted doses to destroy cancer cells while preserving healthy tissue.",
100
- "A group of medical students attend a virtual reality lecture, where they can interact with detailed, 3D anatomical models and simulate complex surgical procedures under the guidance of renowned experts from around the world.",
101
- "In a remote village, a local healthcare worker uses a portable, AI-powered diagnostic device to quickly and accurately assess a patient's symptoms, while seamlessly connecting with specialists in distant cities for expert advice and treatment planning.",
102
- "At an advanced fertility clinic, a couple watches in wonder as an AI-assisted system carefully selects the most viable embryos for implantation, while providing personalized guidance and emotional support throughout the process."
 
 
103
  ]
104
 
105
  css = '''
@@ -110,6 +137,16 @@ visibility: hidden
110
  }
111
  '''
112
 
 
 
 
 
 
 
 
 
 
 
113
  with gr.Blocks(css=css, theme="pseudolab/huggingface-korea-theme") as demo:
114
  gr.Markdown(DESCRIPTION)
115
 
@@ -124,7 +161,6 @@ with gr.Blocks(css=css, theme="pseudolab/huggingface-korea-theme") as demo:
124
  )
125
  run_button = gr.Button("Run", scale=0)
126
  result = gr.Gallery(label="Result", columns=1, preview=True, show_label=False)
127
- gallery = gr.Gallery(label="Gallery", columns=2, rows=2, object_fit="cover", height="auto", show_label=False)
128
  with gr.Accordion("Advanced options", open=False):
129
  use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
130
  negative_prompt = gr.Text(
@@ -183,6 +219,7 @@ with gr.Blocks(css=css, theme="pseudolab/huggingface-korea-theme") as demo:
183
  api_name=False,
184
  )
185
 
 
186
  gr.on(
187
  triggers=[
188
  prompt.submit,
@@ -200,7 +237,7 @@ with gr.Blocks(css=css, theme="pseudolab/huggingface-korea-theme") as demo:
200
  guidance_scale,
201
  randomize_seed,
202
  ],
203
- outputs=[result, seed, gallery],
204
  api_name="run",
205
  )
206
 
 
24
  unique_name = str(uuid.uuid4()) + ".png"
25
  img.save(unique_name)
26
 
27
+ # save with promp to save prompt as image file name
28
  filename = f"{prompt}.png"
29
  img.save(filename)
30
  return filename
31
+
32
+ return unique_name
33
 
34
  def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
35
  if randomize_seed:
 
46
  USE_TORCH_COMPILE = 0
47
  ENABLE_CPU_OFFLOAD = 0
48
 
49
+
50
  if torch.cuda.is_available():
51
  pipe = StableDiffusionXLPipeline.from_pretrained(
52
  "fluently/Fluently-XL-v4",
 
55
  )
56
  pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
57
 
58
+
59
  pipe.load_lora_weights("ehristoforu/dalle-3-xl-v2", weight_name="dalle-3-xl-lora-v2.safetensors", adapter_name="dalle")
60
  pipe.set_adapters("dalle")
61
 
62
  pipe.to("cuda")
63
+
64
+
65
 
66
  @spaces.GPU(enable_queue=True)
67
  def generate(
 
71
  seed: int = 0,
72
  width: int = 1024,
73
  height: int = 1024,
74
+ #width: int = 1920,
75
+ #height: int = 1080,
76
  guidance_scale: float = 3,
77
+ #randomize_seed: bool = True,
78
  randomize_seed: bool = False,
79
  progress=gr.Progress(track_tqdm=True),
80
  ):
81
+
82
+
83
  seed = int(randomize_seed_fn(seed, randomize_seed))
84
 
85
  if not use_negative_prompt:
 
92
  height=height,
93
  guidance_scale=guidance_scale,
94
  num_inference_steps=20,
95
+ #num_inference_steps=50,
96
  num_images_per_prompt=1,
97
+ #cross_attention_kwargs={"scale": 2.00},
98
  cross_attention_kwargs={"scale": 0.65},
99
  output_type="pil",
100
  ).images
101
  image_paths = [save_image(img, prompt) for img in images]
102
+
103
+ #image_paths = [save_image(img) for img in images]
104
  download_links = [create_download_link(path) for path in image_paths]
105
 
106
  print(image_paths)
107
+ #return image_paths, seed
108
  return image_paths, seed, download_links
109
 
110
+ examples_old = [
111
+ "a modern hospital room with advanced medical equipment and a patient resting comfortably",
112
+ "a team of surgeons performing a delicate operation using state-of-the-art surgical robots",
113
+ "a elderly woman smiling while a nurse checks her vital signs using a holographic display",
114
+ "a child receiving a painless vaccination from a friendly robot nurse in a colorful pediatric clinic",
115
+ "a group of researchers working in a high-tech laboratory, developing new treatments for rare diseases",
116
+ "a telemedicine consultation between a doctor and a patient, using virtual reality technology for a immersive experience"
117
+ ]
118
+
119
  examples = [
120
+ #"In a sleek, private hospital suite, a recovering patient relaxes in a luxurious bed while a personalized AI assistant monitors their health, adjusts the ambient lighting, and provides entertainment tailored to their preferences.",
121
+ #"A skilled neurosurgeon leads a team of experts in a groundbreaking brain surgery, utilizing advanced neuronavigation systems and miniaturized robotics to precisely remove a tumor with minimal invasiveness.",
122
+ "An elderly man engages in a virtual reality physical therapy session, guided by a compassionate AI therapist that adapts the exercises to his abilities and provides encouragement, all from the comfort of his own home.",
123
+ "In a bright, welcoming dental office, a young patient watches in awe as a dental robot efficiently and painlessly repairs a cavity using a laser system, while the dentist explains the procedure using interactive 3D images.",
124
+ "A team of biomedical engineers collaborate in a state-of-the-art research facility, designing and testing advanced prosthetic limbs that seamlessly integrate with the patient's nervous system for natural, intuitive control.",
125
+ "A pregnant woman undergoes a routine check-up, as a gentle robotic ultrasound system captures high-resolution 3D images of her developing baby, while the obstetrician provides reassurance and guidance via a holographic display.",
126
+ "In a cutting-edge cancer treatment center, a patient undergoes a precision radiation therapy session, where an AI-guided system delivers highly targeted doses to destroy cancer cells while preserving healthy tissue.",
127
+ "A group of medical students attend a virtual reality lecture, where they can interact with detailed, 3D anatomical models and simulate complex surgical procedures under the guidance of renowned experts from around the world.",
128
+ "In a remote village, a local healthcare worker uses a portable, AI-powered diagnostic device to quickly and accurately assess a patient's symptoms, while seamlessly connecting with specialists in distant cities for expert advice and treatment planning.",
129
+ "At an advanced fertility clinic, a couple watches in wonder as an AI-assisted system carefully selects the most viable embryos for implantation, while providing personalized guidance and emotional support throughout the process."
130
  ]
131
 
132
  css = '''
 
137
  }
138
  '''
139
 
140
+
141
+ #css = '''
142
+ #.gradio-container{max-width: 560px !important}
143
+ #h1{text-align:center}
144
+ #footer {
145
+ # visibility: hidden
146
+ #}
147
+ #'''
148
+
149
+
150
  with gr.Blocks(css=css, theme="pseudolab/huggingface-korea-theme") as demo:
151
  gr.Markdown(DESCRIPTION)
152
 
 
161
  )
162
  run_button = gr.Button("Run", scale=0)
163
  result = gr.Gallery(label="Result", columns=1, preview=True, show_label=False)
 
164
  with gr.Accordion("Advanced options", open=False):
165
  use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
166
  negative_prompt = gr.Text(
 
219
  api_name=False,
220
  )
221
 
222
+
223
  gr.on(
224
  triggers=[
225
  prompt.submit,
 
237
  guidance_scale,
238
  randomize_seed,
239
  ],
240
+ outputs=[result, seed],
241
  api_name="run",
242
  )
243