temp / app.py
AthuKawaleLogituit's picture
Create app.py
f1d31d5 verified
raw
history blame
2.13 kB
import os
import requests
import gradio as gr
from huggingface_hub import Repository
REPO_ID = "AthuKawaleLogituit/Faceswap"
LOCAL_DIR = "models"
urls = [
"https://huggingface.co/countfloyd/deepfake/resolve/main/inswapper_128.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/reswapper_128.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/reswapper_256.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/GFPGANv1.4.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/GPEN-BFR-512.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/restoreformer_plus_plus.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/xseg.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/rd64-uni-refined.pth",
"https://huggingface.co/countfloyd/deepfake/resolve/main/CodeFormerv0.1.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/deoldify_artistic.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/deoldify_stable.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/isnet-general-use.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/real_esrgan_x4.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/real_esrgan_x2.onnx",
"https://huggingface.co/countfloyd/deepfake/resolve/main/lsdir_x4.onnx"
]
def download_and_upload():
os.makedirs(LOCAL_DIR, exist_ok=True)
for url in urls:
filename = os.path.join(LOCAL_DIR, os.path.basename(url))
if not os.path.exists(filename):
r = requests.get(url, allow_redirects=True)
with open(filename, 'wb') as f:
f.write(r.content)
token = os.environ.get("HF_TOKEN")
repo = Repository(local_dir=LOCAL_DIR, clone_from=REPO_ID, use_auth_token=token)
repo.git_add()
repo.git_commit("Upload model files from Gradio Space")
repo.git_push()
return "✅ Models downloaded and pushed to Faceswap repo."
gr.Interface(fn=download_and_upload, inputs=[], outputs="text", title="Upload Faceswap Models").launch()