test-stfzip / app.py
yerang's picture
Update app.py
5a51b84 verified
raw
history blame
1.75 kB
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()