Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
import os
|
2 |
import requests
|
3 |
import gradio as gr
|
4 |
-
from huggingface_hub import
|
5 |
|
6 |
REPO_ID = "AthuKawaleLogituit/Faceswap"
|
|
|
7 |
LOCAL_DIR = "models"
|
8 |
|
9 |
urls = [
|
@@ -24,22 +25,36 @@ urls = [
|
|
24 |
"https://huggingface.co/countfloyd/deepfake/resolve/main/lsdir_x4.onnx"
|
25 |
]
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
def download_and_upload():
|
28 |
os.makedirs(LOCAL_DIR, exist_ok=True)
|
|
|
29 |
|
30 |
for url in urls:
|
31 |
-
filename = os.path.
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
44 |
|
45 |
gr.Interface(fn=download_and_upload, inputs=[], outputs="text", title="Upload Faceswap Models").launch()
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
import gradio as gr
|
4 |
+
from huggingface_hub import upload_file, HfFolder
|
5 |
|
6 |
REPO_ID = "AthuKawaleLogituit/Faceswap"
|
7 |
+
TOKEN = os.environ.get("HF_TOKEN")
|
8 |
LOCAL_DIR = "models"
|
9 |
|
10 |
urls = [
|
|
|
25 |
"https://huggingface.co/countfloyd/deepfake/resolve/main/lsdir_x4.onnx"
|
26 |
]
|
27 |
|
28 |
+
def download_file(url, filepath):
|
29 |
+
print(f"Downloading {url}")
|
30 |
+
with requests.get(url, stream=True, allow_redirects=True) as r:
|
31 |
+
r.raise_for_status()
|
32 |
+
with open(filepath, 'wb') as f:
|
33 |
+
for chunk in r.iter_content(chunk_size=8192):
|
34 |
+
if chunk:
|
35 |
+
f.write(chunk)
|
36 |
+
|
37 |
def download_and_upload():
|
38 |
os.makedirs(LOCAL_DIR, exist_ok=True)
|
39 |
+
uploaded_files = []
|
40 |
|
41 |
for url in urls:
|
42 |
+
filename = os.path.basename(url)
|
43 |
+
local_path = os.path.join(LOCAL_DIR, filename)
|
44 |
+
|
45 |
+
if not os.path.exists(local_path):
|
46 |
+
download_file(url, local_path)
|
47 |
+
|
48 |
+
# Upload to repo
|
49 |
+
upload_file(
|
50 |
+
path_or_fileobj=local_path,
|
51 |
+
path_in_repo=filename,
|
52 |
+
repo_id=REPO_ID,
|
53 |
+
repo_type="model",
|
54 |
+
token=TOKEN
|
55 |
+
)
|
56 |
+
uploaded_files.append(filename)
|
57 |
+
|
58 |
+
return f"✅ Uploaded files: {uploaded_files}"
|
59 |
|
60 |
gr.Interface(fn=download_and_upload, inputs=[], outputs="text", title="Upload Faceswap Models").launch()
|