Spaces:
Running
on
L40S
Running
on
L40S
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import torch
|
2 |
import os
|
3 |
-
import tarfile
|
4 |
-
import requests
|
5 |
import shutil
|
6 |
import tempfile
|
7 |
import gradio as gr
|
@@ -13,47 +11,6 @@ from glob import glob
|
|
13 |
import requests
|
14 |
from huggingface_hub import snapshot_download
|
15 |
|
16 |
-
# Define the URL and destination paths
|
17 |
-
onedrive_url = "https://hkustconnect-my.sharepoint.com/:u:/g/personal/plibp_connect_ust_hk/EZQphP-2y5BGhEIe8jb03i4BIcqiJ2mUW2JmGC5s0VKOdw?e=qVzBBD"
|
18 |
-
destination_tar = "smpl_related.tar.gz"
|
19 |
-
destination_folder = "smpl_related"
|
20 |
-
|
21 |
-
# Download the file
|
22 |
-
def download_file(url, destination):
|
23 |
-
print(f"Downloading {url} to {destination}...")
|
24 |
-
response = requests.get(url, stream=True)
|
25 |
-
if response.status_code == 200:
|
26 |
-
with open(destination, 'wb') as f:
|
27 |
-
f.write(response.content)
|
28 |
-
print(f"Downloaded file to {destination}")
|
29 |
-
else:
|
30 |
-
raise Exception(f"Failed to download file. Status code: {response.status_code}")
|
31 |
-
|
32 |
-
# Extract the tar.gz file
|
33 |
-
def extract_tar(file_path, extract_to):
|
34 |
-
print(f"Extracting {file_path} to {extract_to}...")
|
35 |
-
with tarfile.open(file_path, "r:gz") as tar:
|
36 |
-
tar.extractall(path=extract_to)
|
37 |
-
print(f"Extraction completed.")
|
38 |
-
|
39 |
-
# Ensure the folder exists
|
40 |
-
if not os.path.exists(destination_folder):
|
41 |
-
try:
|
42 |
-
# Step 1: Download the tar.gz file
|
43 |
-
download_file(onedrive_url, destination_tar)
|
44 |
-
|
45 |
-
# Step 2: Extract the tar.gz file
|
46 |
-
extract_tar(destination_tar, "./")
|
47 |
-
|
48 |
-
# Step 3: Clean up the tar.gz file after extraction
|
49 |
-
os.remove(destination_tar)
|
50 |
-
print(f"Cleaned up the tar file: {destination_tar}")
|
51 |
-
|
52 |
-
except Exception as e:
|
53 |
-
print(f"An error occurred: {e}")
|
54 |
-
else:
|
55 |
-
print(f"Folder {destination_folder} already exists. Skipping download and extraction.")
|
56 |
-
|
57 |
# Download models
|
58 |
os.makedirs("ckpts", exist_ok=True)
|
59 |
|
@@ -62,6 +19,12 @@ snapshot_download(
|
|
62 |
local_dir = "./ckpts"
|
63 |
)
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
def remove_background(input_url):
|
67 |
# Create a temporary folder for downloaded and processed images
|
|
|
1 |
import torch
|
2 |
import os
|
|
|
|
|
3 |
import shutil
|
4 |
import tempfile
|
5 |
import gradio as gr
|
|
|
11 |
import requests
|
12 |
from huggingface_hub import snapshot_download
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Download models
|
15 |
os.makedirs("ckpts", exist_ok=True)
|
16 |
|
|
|
19 |
local_dir = "./ckpts"
|
20 |
)
|
21 |
|
22 |
+
os.makedirs("smpl_related", exist_ok=True)
|
23 |
+
snapshot_download(
|
24 |
+
repo_id = "fffiloni/PSHuman-SMPL-related",
|
25 |
+
local_dir = "./smpl_related"
|
26 |
+
)
|
27 |
+
|
28 |
|
29 |
def remove_background(input_url):
|
30 |
# Create a temporary folder for downloaded and processed images
|