刘虹雨 commited on
Commit
32fac76
·
1 Parent(s): 2f24813

update code

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -91,7 +91,6 @@ def install_cuda_toolkit():
91
 
92
  # 🔧 Set CUDA_HOME before anything else
93
 
94
-
95
  # Configure logging settings
96
  logging.basicConfig(
97
  level=logging.INFO,
@@ -593,7 +592,7 @@ def assert_input_image(input_image):
593
  if input_image is None:
594
  raise gr.Error("No image selected or uploaded!")
595
 
596
-
597
  def process_image(input_image, source_type, is_style, save_dir):
598
  """ 🎯 处理 input_image,根据是否是示例图片执行不同逻辑 """
599
  process_img_input_dir = os.path.join(save_dir, 'input_image')
@@ -678,7 +677,6 @@ css = """
678
  """
679
 
680
  def launch_gradio_app():
681
- install_cuda_toolkit()
682
  styles = {
683
  "Ghibli": "Ghibli style avatar, anime style",
684
  "Pixar": "a 3D render of a face in Pixar style",
@@ -940,11 +938,26 @@ def launch_gradio_app():
940
 
941
  demo.queue()
942
  demo.launch(server_name="0.0.0.0")
 
 
 
 
 
943
 
 
944
 
945
  if __name__ == '__main__':
946
  import torch.multiprocessing as mp
947
  mp.set_start_method('spawn', force=True)
 
 
 
 
 
 
 
 
 
948
  launch_pretrained()
949
  image_folder = "./demo_data/source_img/img_generate_different_domain/images512x512/demo_imgs"
950
  example_img_names = os.listdir(image_folder)
 
91
 
92
  # 🔧 Set CUDA_HOME before anything else
93
 
 
94
  # Configure logging settings
95
  logging.basicConfig(
96
  level=logging.INFO,
 
592
  if input_image is None:
593
  raise gr.Error("No image selected or uploaded!")
594
 
595
+ @spaces.GPU(duration=100)
596
  def process_image(input_image, source_type, is_style, save_dir):
597
  """ 🎯 处理 input_image,根据是否是示例图片执行不同逻辑 """
598
  process_img_input_dir = os.path.join(save_dir, 'input_image')
 
677
  """
678
 
679
  def launch_gradio_app():
 
680
  styles = {
681
  "Ghibli": "Ghibli style avatar, anime style",
682
  "Pixar": "a 3D render of a face in Pixar style",
 
938
 
939
  demo.queue()
940
  demo.launch(server_name="0.0.0.0")
941
+ def _get_output(cmd):
942
+ try:
943
+ return subprocess.check_output(cmd).decode("utf-8")
944
+ except Exception as ex:
945
+ logging.exception(ex)
946
 
947
+ return None
948
 
949
  if __name__ == '__main__':
950
  import torch.multiprocessing as mp
951
  mp.set_start_method('spawn', force=True)
952
+ logging.info("Environment Variables: %s" % os.environ)
953
+ logging.info("Installing CUDA extensions...")
954
+ if _get_output(["nvcc", "--version"]) is None:
955
+ logging.info("Installing CUDA toolkit...")
956
+ install_cuda_toolkit()
957
+ else:
958
+ logging.info("Detected CUDA: %s" % _get_output(["nvcc", "--version"]))
959
+
960
+
961
  launch_pretrained()
962
  image_folder = "./demo_data/source_img/img_generate_different_domain/images512x512/demo_imgs"
963
  example_img_names = os.listdir(image_folder)