import gradio as gr import spaces import torch import gdown import os import setup_environment import zipfile from setup_environment import initialize_environment zero = torch.Tensor([0]).cuda() print(zero.device) # <-- 'cpu' 🤔 @spaces.GPU def greet(n): print(zero.device) # <-- 'cuda:0' 🤗 # 다운로드할 파일의 공유 링크 #file_id = 'your_file_id_here' file_id=os.getenv('ZIPFILE_ID') url = f"https://drive.google.com/uc?id={file_id}" # 파일 다운로드 gdown.download(url, '/tmp/stf.zip', quiet=False) dir_zip= os.path.join(root_path, '/tmp/stf.zip') dir_target=os.path.join(root_path,'/tmp/') zipfile.ZipFile(dir_zip, 'r').extractall(dir_target) initialize_environment() sys.path.append('/home/user/.local/lib/python3.10/site-packages') sys.path.append('/home/user/.local/lib/python3.10/site-packages/stf_alternative/src/stf_alternative') sys.path.append('/home/user/.local/lib/python3.10/site-packages/stf_tools/src/stf_tools') sys.path.append('/tmp/') sys.path.append('/tmp/stf/') sys.path.append('/tmp/stf/stf_alternative/') sys.path.append('/tmp/stf/stf_alternative/src/stf_alternative') # CUDA 경로를 환경 변수로 설정 os.environ['PATH'] = '/usr/local/cuda/bin:' + os.environ.get('PATH', '') os.environ['LD_LIBRARY_PATH'] = '/usr/local/cuda/lib64:' + os.environ.get('LD_LIBRARY_PATH', '') # 확인용 출력 print("PATH:", os.environ['PATH']) print("LD_LIBRARY_PATH:", os.environ['LD_LIBRARY_PATH']) from stf_utils import STFPipeline return f"Hello {zero + n} Tensor" demo = gr.Interface(fn=greet, inputs=gr.Number(), outputs=gr.Text()) demo.launch()