Hpsoyl commited on
Commit
d7b90f6
·
1 Parent(s): cb29951
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -15,6 +15,7 @@ import shutil
15
  import time
16
  import torch.nn as nn
17
  import torch.nn.functional as F
 
18
  from collections import OrderedDict
19
 
20
 
@@ -263,6 +264,7 @@ def swap_t2i_unet(pipe, target_unet_path):
263
  # if not os.path.exists(example_filepath):
264
  # generated_image.save(example_filepath); print(f"✓ New T2I example saved: {example_filepath}")
265
  # return generated_image
 
266
  def generate_t2i(prompt, num_inference_steps):
267
  global t2i_pipe
268
  if t2i_pipe is None: raise gr.Error("Text-to-Image model is not loaded.")
@@ -282,6 +284,7 @@ def generate_t2i(prompt, num_inference_steps):
282
  print(f"✓ New T2I example saved: {example_filepath}")
283
  return generated_image
284
 
 
285
  def run_mask_to_image_generation(mask_file_obj, cell_type, num_images, steps, seed):
286
  if controlnet_pipe is None: raise gr.Error("ControlNet pipeline is not loaded.")
287
  if mask_file_obj is None: raise gr.Error("Please upload a segmentation mask TIF file.")
@@ -322,6 +325,7 @@ def run_mask_to_image_generation(mask_file_obj, cell_type, num_images, steps, se
322
 
323
  return input_display_image, generated_images_pil
324
 
 
325
  def run_super_resolution(low_res_file_obj, controlnet_model_name, prompt, steps, seed):
326
  if controlnet_pipe is None: raise gr.Error("ControlNet pipeline is not loaded.")
327
  if low_res_file_obj is None: raise gr.Error("Please upload a low-resolution TIF file.")
@@ -358,6 +362,7 @@ def run_super_resolution(low_res_file_obj, controlnet_model_name, prompt, steps,
358
 
359
  return input_display_image, numpy_to_pil(output_np)
360
 
 
361
  def run_denoising(noisy_image_np, image_type, steps, seed):
362
  if controlnet_pipe is None: raise gr.Error("ControlNet pipeline is not loaded.")
363
  if noisy_image_np is None: raise gr.Error("Please upload a noisy image.")
@@ -387,6 +392,7 @@ def run_denoising(noisy_image_np, image_type, steps, seed):
387
 
388
  return numpy_to_pil(noisy_image_np, "L"), numpy_to_pil(output_np)
389
 
 
390
  def run_segmentation(input_image_np, model_name, diameter, flow_threshold, cellprob_threshold):
391
  """
392
  Runs cell segmentation and creates a dark red overlay.
@@ -459,6 +465,7 @@ def run_segmentation(input_image_np, model_name, diameter, flow_threshold, cellp
459
 
460
  return numpy_to_pil(input_image_np, "L"), numpy_to_pil(blended_image_np, "RGB")
461
 
 
462
  def run_classification(input_image_np, model_name):
463
  """
464
  Runs classification on a single image using a pre-trained ResNet50 model.
 
15
  import time
16
  import torch.nn as nn
17
  import torch.nn.functional as F
18
+ import spaces
19
  from collections import OrderedDict
20
 
21
 
 
264
  # if not os.path.exists(example_filepath):
265
  # generated_image.save(example_filepath); print(f"✓ New T2I example saved: {example_filepath}")
266
  # return generated_image
267
+ @spaces.GPU(duration=120)
268
  def generate_t2i(prompt, num_inference_steps):
269
  global t2i_pipe
270
  if t2i_pipe is None: raise gr.Error("Text-to-Image model is not loaded.")
 
284
  print(f"✓ New T2I example saved: {example_filepath}")
285
  return generated_image
286
 
287
+ @spaces.GPU(duration=120)
288
  def run_mask_to_image_generation(mask_file_obj, cell_type, num_images, steps, seed):
289
  if controlnet_pipe is None: raise gr.Error("ControlNet pipeline is not loaded.")
290
  if mask_file_obj is None: raise gr.Error("Please upload a segmentation mask TIF file.")
 
325
 
326
  return input_display_image, generated_images_pil
327
 
328
+ @spaces.GPU(duration=120)
329
  def run_super_resolution(low_res_file_obj, controlnet_model_name, prompt, steps, seed):
330
  if controlnet_pipe is None: raise gr.Error("ControlNet pipeline is not loaded.")
331
  if low_res_file_obj is None: raise gr.Error("Please upload a low-resolution TIF file.")
 
362
 
363
  return input_display_image, numpy_to_pil(output_np)
364
 
365
+ @spaces.GPU(duration=120)
366
  def run_denoising(noisy_image_np, image_type, steps, seed):
367
  if controlnet_pipe is None: raise gr.Error("ControlNet pipeline is not loaded.")
368
  if noisy_image_np is None: raise gr.Error("Please upload a noisy image.")
 
392
 
393
  return numpy_to_pil(noisy_image_np, "L"), numpy_to_pil(output_np)
394
 
395
+ @spaces.GPU(duration=120)
396
  def run_segmentation(input_image_np, model_name, diameter, flow_threshold, cellprob_threshold):
397
  """
398
  Runs cell segmentation and creates a dark red overlay.
 
465
 
466
  return numpy_to_pil(input_image_np, "L"), numpy_to_pil(blended_image_np, "RGB")
467
 
468
+ @spaces.GPU(duration=120)
469
  def run_classification(input_image_np, model_name):
470
  """
471
  Runs classification on a single image using a pre-trained ResNet50 model.